问题描述
我有这个 System::Windows::Forms::Panel,我想启用它,这样如果用户单击并拖动鼠标,就会将窗口拖到周围。
我可以这样做吗?我是否必须实现多个事件?
解决方法
我建议您尝试拨打 Control.MouseDown Event 和 Control.MouseMove Event
这是我的代码,我建议你可以参考:
Point pt;
private: System::Void panel1_MouseDown(System::Object^ sender,System::Windows::Forms::MouseEventArgs^ e)
{
Point mouseDownLocation = Point(e->X,e->Y);
pt = Cursor->Position;
}
private: System::Void panel1_MouseMove(System::Object^ sender,System::Windows::Forms::MouseEventArgs^ e)
{
if (e->Button == System::Windows::Forms::MouseButtons::Left)
{
int px = Cursor->Position.X - pt.X;
int py = Cursor->Position.Y - pt.Y;
panel1->Location = System::Drawing::Point(panel1->Location.X + px,panel1->Location.Y + py);
pt = Cursor->Position;
}