Board index » cppbuilder » Moving a TShape on a form

Moving a TShape on a form


2006-05-20 07:44:51 AM
cppbuilder91
Can someone help me?
I would like to be able to move a TShape around on a form, but have
not been able to get this to work properly.
Has anyone ever done this with an OnMouseDown event?
 
 

Re:Moving a TShape on a form

Hi {*word*104}man ,
in the private section of your form
int initX, initY;
and
then use the MouseDown and MouseMove events of TShape
//---------------------------------------------------------------------------
void __fastcall TForm1::Shape1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
initX = X;
initY = Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Shape1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if (Shift.Contains(ssLeft)){
Shape1->Top = Shape1->Top + (Y- initY);
Shape1->Left = Shape1->Left + (X-initX );
}
}
//---------------------------------------------------------------------------
regards
_minas
------
"Only virtue's conquests have certainty" Sofokleous Erephyle
www.e-grammes.gr/index_en.html
 

Re:Moving a TShape on a form

Minas wrote:
Quote
in the private section of your form

int initX, initY;

and
then use the MouseDown and MouseMove events of TShape
I'd respectfully suggest you add code to ensure the MouseMove handler
does not act until the MouseDown event is first detected to initialize
initX and initY. Otherwise you can get anomalous initial motion.
-- V
 

{smallsort}