首先,你要知道被拖放控件的名字,如果有很多Class(类)相同的控件要拖放,而且关联相同的函数,此时你就要利用控件名字来区分不同的控件。
在以往的版本中如bcb6中,要拖放的控件如果设置为DragMode=alAutomatic时,可以响应MouseDonw函数。利用该响应,可以获得激活的控件名字。但在xe7下,就无法响应MouseDown了。怎么办呢?
利用了xe6就增了MouseMove函数,可以解决该问题。
TRectangle *ActiveObj;//因为下面要用到TRectangle类,用户可以将其定义为其他为类。
void __fastcall TForm3D1::ZhaoYunMouseMove(TObject *Sender, TShiftState Shift, float X, float Y)
{
if(ActiveObj !=NULL) ((TButton *)ActiveObj)->TintColor =TAlphaColor(NULL);
((TButton *)Sender)->TintColor = TAlphaColor(claYellowgreen);
ActiveObj = ((TButton *)Sender);//自定义的TButton *ActiveObj;
}
//---------------------------------------------------------------------------
然后在包容控件中的DragDrop事件中进行相应的处理。
void __fastcall TForm3D1::BoardDragOver(TObject *Sender, const TDragObject &Data, const TPointF &Point, TDragOperation &Operation)
{
BoardDrag(Sender, Point.X,Point.Y);//自定义函数,也可以直接写上自己的代码。
}
//---------------------------------------------------------------------------
以上是鼠标按住不放进行拖动时的处理,也可以点击处理的,即前先击要拖放的控件,然后在点击包含控件,效果一样。
void __fastcall TForm3D1::BoardMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
float X, float Y)
{
BoardDrag(Sender, X,Y);
}
//---------------------------------------------------------------------------