领悟旧事

Learned Helplessness
分类新闻>>技术文章>>
在XE6/XE7中如何拖放控件?
来源:http://www.xx0594.com/
时间:2014-12-30
作者:  浏览人数:893
在XE6/XE7中如何拖放控件?

    首先,你要知道被拖放控件的名字,如果有很多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);
}
//---------------------------------------------------------------------------

关闭窗口
 访问量:508185
任何第三方若要引用、转摘本站信息,均需征得本站书面同意,否则视为侵权。本站信息为个人观点,若因引用本站信息而产生的任何情况,均与本站无关。Email:linmutou@163.com
闽ICP备14017840号-2