#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Moving an image over a control while staying in the forground at runtime


    My application lets the user move an image anywhere on the forum.
    The move is triggered by a mousedown event and processed by
    the mousemove event of the timage being moved. It basically
    just follows the cursor by adding x and y values to Left and top
    of the image giving the appearance that the image is being dragged and follows the cursor. All is well with this until the image
    comes in contact with a control such as a tbutton or a tlistbox.

    When this occurs the image "Disappears" behind the control.
    "Send to back" has no effect on the scenario. Is there a
    method or procedure that can enable the move object(timage) to
    remain visible as it is moved over a control ?

    Note1: "Send to back" works if I wish to move one control
    over another control, but not with an Image over a control.

    Note2: If the situation is changed to implementing the move using Dragging, the Drag Object will stay in the foreround during
    the process. However this is not a desirable solution as the behavior is different between situations. In moving the object it will stay "Solid" as it is being moved. The drag creates a transparent image in all methods i have tried. I want the solid.

    When dragging the DragObject it can be "dragged off" the form and
    if released there is no event triggered. In moving the object the image can not be moved off of the form so it is guaranteed
    to have an event triggered at some point (Mouse up eventually)

    Any ideas would be appreciated. It seemed like such a trivial thing when i started looking at this a few days ago now its a
    seems its a bit more complex Thanks

    Gil MacDougall
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    354
    Rep Power
    7
    I haven't tried this but possibly if you put the image component on a panel (set the image align property to alclient) then move the panel via the same logic as you did for the image.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Great Idea majlumbo !


    Originally Posted by majlumbo
    I haven't tried this but possibly if you put the image component on a panel (set the image align property to alclient) then move the panel via the same logic as you did for the image.
    I tried the Tpanel suggestion and it worked ! Thanks! I will
    have to recode parts of my application to reference tpanel
    but it should work. I really never thought about this behavior
    until after i had wrote code involving the images.

    For anyone following this thread the solution for moving of the image object was tweaked on by majlumba(kudos).

    In most code you find for moving controls the process makes
    use of a handle to move the object. I knew i could not use a
    handle for an image as it has none. So i implemented a procedure
    that just moved the object with x and y from the mousemove
    (as i stated in question) It did not dawn on me until majlumbos idea about the panel that using a handle was possible if the image is embedded in a control such as a panel. I went back and placed my image on a panel then the "normal" code used to move objects could be used to move the panel with the image.

    Summary:

    {code in TPanel was derived from this
    as a new memeber i can not paste url so here is code
    it uses a button and a radio group to toggle drag on and off
    in my case the button code was used as the panel code}

    private
    { Private declarations }
    public
    { Public declarations }

    OldPos: TPoint;
    end;

    //****************
    type
    TForm1 = class(TForm)
    ...
    private
    { Private declarations }
    Dragged: Boolean;
    OldPos: TPoint;
    ...

    procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    if RadioGroup1.ItemIndex=0 then
    begin
    Dragged:=True;
    GetCursorPos(OldPos);
    SetCapture(Button1.Handle);
    end;
    end;

    procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
    Y: Integer);
    var
    NewPos: TPoint;
    begin
    if Dragged then
    with Button1 do
    begin
    GetCursorPos(NewPos);
    Left:=Left-OldPos.X+NewPos.X;
    Top:=Top-OldPos.Y+NewPos.Y;
    OldPos:=NewPos;
    end;
    end;

    procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    begin
    if Dragged then
    begin
    ReleaseCapture;
    Dragged:=False;
    end;
    end;
    //******************

    Paste image on panel
    set panel properties:

    border :none
    height := image.height
    width := image.width

    image properties:
    align = none
    left = 0
    top = 0

    assign the MouseDown,MouseMove,MouseUp events
    of the TIMAGE to use the corresponding events of
    the Tpanel(that actually has the code).

    Set Doublebuffering := true in form create to reduce flickering.

    Thanks again majlumbo !

IMN logo majestic logo threadwatch logo seochat tools logo