954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Move TShape Over a Panel

Hi,

My front end has a Tshape(Cirle) Over a Panel and I am trying to move the circle on the panel and get the X and Y values and send these values through comport for serial communication.

However I am able to retrieve the values but the shape is flickering when I move it over the panel and it finally disappears.I am having the shape at the center of the 120*120 panel and having the center of the shape as 0*0. When I move the shape towards the left I should be getting -60 to 0 and towards right 0 to 60, similarly for the Y axis. And the shape should stay at the position where I left it through the mouse move.

Any Help greatly appreciated.

Regards

Deepika_KR
Light Poster
41 posts since Aug 2008
Reputation Points: 10
Solved Threads: 3
 

Show your code. Hard to guess your problem without it.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 874
 
Show your code. Hard to guess your problem without it.
procedure TForm4.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);

//Shape is placed on the panel with width and top as 120*120
  var
  int1: integer;
  int2: integer;
begin

if ssleft in shift then
begin

  int1:= shape1.Left;
  int2:= shape1.Top;

  pitchedit.Text:= inttostr(int1+X);
  rolledit.Text:= inttostr(int2+Y);
  Shape1.Left:= int1+X;
  Shape1.Top:= int2+Y;

end;
end;


Hey..Now I am able to move the shape over the panel smoothly but it is however having the top left of the panel as zero reference point, how do I make it have the center of the TShape as 0*0

Deepika_KR
Light Poster
41 posts since Aug 2008
Reputation Points: 10
Solved Threads: 3
 

Shift the coordinates with half the width and half the height.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 874
 

Hi, below is the code to have the shape move over the panel on mouse click over it, but could you please let me know how to limit the shape to just move around the panel and not out of it. Now I am able to move it outside the panel even though it is not visible outside, the value changes in the edit box.

procedure TInteractiveP.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);

var
 rl1, rl2 : Real;

begin
  if ssleft in shift then
    begin
      rl1:= shape1.Left+X/10;
      rl2:= shape1.Top+Y/10;
    if(rl1> 60) then
      begin
        rl1:= 60-rl1;
        pitchedit.Text:= floattostr(rl1);
        Statusbar1.Panels[0].Text:= 'Pitch Value is '+ floattostr(rl1);
      end
    else
      pitchedit.Text:= floattostr(rl1);
      Statusbar1.Panels[0].Text:= 'Pitch Value is '+ floattostr(rl1);
      if (rl2> 60) then
        begin
          rl2:= 60-rl2;
          rolledit.Text:= floattostr(rl2);
          Statusbar1.panels[1].Text:= 'Roll Value is '+ floattostr(rl2);
        end
      else
        rolledit.Text:= floattostr(rl2);
        Statusbar1.Panels[1].Text:= 'Roll Value is '+ floattostr(rl2);
        Shape1.Left:= trunc(shape1.left+X/10);
        Shape1.Top:= trunc(shape1.top+Y/10);
      end;
end;
Deepika_KR
Light Poster
41 posts since Aug 2008
Reputation Points: 10
Solved Threads: 3
 

When you assign a new left and top, you can check whether or not it falls of the panel. If so, do not update the left and top.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 874
 

Thank you...

Deepika_KR
Light Poster
41 posts since Aug 2008
Reputation Points: 10
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: