WinForm拖动没有标题栏窗体的方法

时间:2023-03-09 02:14:54
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;
}
}

效果图:
WinForm拖动没有标题栏窗体的方法

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

源码下载:

http://hovertree.com/h/bjaf/j4wwteu3.htm

转自:http://hovertree.com/h/bjaf/qewlrgqx.htm

推荐:

http://www.cnblogs.com/roucheng/p/DataGridView.html

相关文章