您的位置:首页 - 教程 - WinForm - 正文
winform拖动无边框窗体

建立窗体的名称修改为:Form_HoverTree

文后附有源码下载。

主要代码:

Point _HoverTreePosition;
public Form_HoverTree()
{
InitializeComponent();
_HoverTreePosition = new Point();

}

/// <summary>
/// 记录鼠标起始位置 hovertree.com
/// </summary>
private void Form_HoverTree_MouseDown(object sender, MouseEventArgs e)
{
_HoverTreePosition.X = e.X;
_HoverTreePosition.Y = e.Y;
}

/// <summary>
/// 按住左键,鼠标移动窗体跟着移动 - 何问起
/// </summary>
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;
}
}


效果图:


可以看出,这个窗体为自定义形状的窗体,没有标题栏。具体参考:http://hovertree.com/h/bjaf/52nadvt4.htm

源码下载:
http://hovertree.com/h/bjaf/j4wwteu3.htm

评论: