C ++ Draggable无边框表格

时间:2011-10-25 01:50:14

标签: c++ winforms visual-studio-2010

好吧,我正在Microsoft Visual Studio C ++ 2010中制作一个简单的便笺应用程序(Winodws Forms) in C ++ 。 我正试图制作一个可拖动的无边框形式。 我现在的代码是:

private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
this->dragging = false;
}

private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->dragging = true;
this->offset = Point(e->X, e->Y);

}


private: System::Void Form1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
if (this->dragging)
{
Point currentScreenPos = PointToScreen(e->Location);
Location = Point(currentScreenPos.X - this->offset.X, currentScreenPos.Y - this->offset.Y);
}

}

private: System::Void Form1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->dragging = false;
}

这对我不起作用。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

不要手动跟踪鼠标,而是让操作系统为您完成。截取WM_NCHITTEST并返回HTCAPTION。或者,仅使用MouseDown事件,向窗口发送特殊的WM_SYSCOMMAND/SC_DRAG消息。有关拖动无边框和/或无标题窗口的MSDN有很多信息。