1. 程式人生 > >Winform去掉標題欄後移動窗體

Winform去掉標題欄後移動窗體

聲明 pos see set hovertree OS cat private sep

第一步:聲明全局變量-> private Point _HoverTreePosition;

第二步:

#region 隱藏標題欄後移動窗口
private void Form_HoverTree_MouseDown(object sender, MouseEventArgs e)
{
_HoverTreePosition.X = e.X;
_HoverTreePosition.Y = e.Y;
}

private void Form_HoverTree_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point h_myPosittion = MousePosition;
h_myPosittion.Offset(-_HoverTreePosition.X, -_HoverTreePosition.Y);
Location = h_myPosittion;
}
}
#endregion

第三步:在窗體上綁定MouseDown、MouseMove兩個方法

Winform去掉標題欄後移動窗體