Results 1 to 10 of 10

Thread: Position Problems

  1. #1

    Position Problems

    Its been bugging me like crazy that there isn't a .right and .bottom attribute to a TImage component(and quite a few other components strangely enough). I assumed .Right would be something like: Right := (component.left + component.width) and that bottom would be something simialer, although this doesn't seem to accurate. What are your thoughts?

  2. #2

    Re: Position Problems

    Use the Height, Top, Width & Left properties

    To move:

    Left: Image.left := image.left -10
    Up: Image.Top := image.top -10
    Right: image.left := image.left + 10
    Down: image.Top := image.top + 10

    Wake up from the dream and live your life to the full

  3. #3

    Re: Position Problems

    To get right and bottom?

  4. #4

    Re: Position Problems

    To get the right I would imagine: Right := image.left + image.width and to get bottom would be Bottom := Image.top + image.height. Hope this helps

    Something like:

    Code:
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var Right, Bottom : integer;
      ResultRight, ResultBottom : string;
    begin
     Right := image1.Left + image1.Width;
     Bottom := image1.Top + image1.Height;
     ResultRight := IntToStr(Right);
     ResultBottom := IntToStr(Bottom);
     LabelRight.Caption := ResultRight;
     LabelLeft.Caption := ResultBottom;
    end;
    Wake up from the dream and live your life to the full

  5. #5

    Re: Position Problems

    It doesn't seem to work.
    What I wanted to use the bottom and right for is to check whether an image component has gone off the screen.

    In pseudo code:
    Repeat
    Image.Left/Top := Image.Left/Top + 1;// If this was -1 then 0 would suffice
    Until Image has gone off the screen // when checking if the image had gone off screen

    I hope it makes sense

  6. #6

    Re: Position Problems

    hi!

    i would say you have to check the following four conditions:
    1. the object can't leave the screen to the left
    2. the object can't leave the screen to the top
    3. the object can't leave the screen to the right
    4. the object can't leave the screen to the bottom

    i would suppose your 'object' is an image too, with a top/left and a height/width, and in my example 'landscape' is an image too:

    checking routine (from head):
    Code:
    //move-code
    
    //check positions
    if object.left< landscape.left then begin
     object.left:= landscape.left;
    end;
    if object.top< landscape.top then begin
     object.top:= landscape.top;
    end;
    if object.left> landscape.left+ landscape.width- object.width then begin
     object.left:= landscape.left+ landscape.width- object.width;
    end;
    if object.top> landscape.top+ landscape.height then begin
     object.top:= landscape.top+ landscape.height- object.top;
    end;

  7. #7

    Re: Position Problems

    and in the special case above, i would say it could be the following if i understood you right:

    Code:
    while (object.top<= landscape.top+ landscape.height) do begin
     object.Top:= object.Top+ 1;
    end;

  8. #8

    Re: Position Problems

    Maybe something like this -- to check that the image doesn't move over the forms right or left border:

    Code:
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
     if (image1.Left >= Form1.Width - 200) then form1.x_Corner := true; 
     if (image1.Left <= 100) then form1.x_Corner := false; 
     if form1.x_Corner then
     image1.Left := image1.Left - 100
     else
     image1.Left := image1.Left + 100;
    end;
    Where x_Corner : boolean; in your forms public declaration. The value 200 and 100 changes according to your image and form...

    More or less the same for y (top & bottom)...
    Wake up from the dream and live your life to the full

  9. #9

    Re: Position Problems

    I will visualize...
    Say we have TImage component with values:
    .left:=2;
    .width:=4;
    So if i draw the coverage in pixels, it looks like:
    Code:
    01234567
    ..xxxx..
    ...which tells us that .right is at 5
    So .right is 2+4-1 that is (.left + .width - 1)

    And same logic in Y-direction .bottom = (.top + .height - 1)

  10. #10

    Re: Position Problems

    Thanks!!
    I'll try these out as soon as possible

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •