this.FormBorderStyle = FormBorderStyle.None; #region窗体移动功能第一种 privatebool blnState = false; privatevoid MoveFrom_MouseDown(object sender, MouseEventArgs e) { blnState = true; ox = e.X; oy = e.Y; } intox = 0; intoy = 0; privatevoid MoveFrom_MouseMove(object sender, MouseEventArgs e) { try { if (blnState) { this.Location = new Point(this.Location.X- (ox - e.X), this.Location.Y - (oy - e.Y)); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } private voidMoveFrom_MouseUp(object sender, MouseEventArgs e) { blnState = false; } #endregion #region无边框窗体移动 第二种 privatePoint mouseOffset; //记录鼠标指针的坐标 privatebool isMouseDown = false;//记录鼠标按键是否按下 ///---------------添加三个关于鼠标的事件 privatevoid Frm_Knowledge_Search_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { intxOffset; intyOffset; if(e.Button == MouseButtons.Left) { xOffset = -e.X - SystemInformation.FrameBorderSize.Width; yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset = new Point(xOffset,yOffset); isMouseDown = true; } } privatevoid Frm_Knowledge_Search_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private voidFrm_Knowledge_Search_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e) { //修改鼠标状态isMouseDown的值 //确保只有鼠标左键按下并移动时,才移动窗体 if(e.Button == MouseButtons.Left) { isMouseDown = false; } } #endregion
C# 将窗口标题栏处除 并可移动窗体
精选 转载demon2012d 博主文章分类:WinForm
文章标签 C# 将窗口标题栏处除 并可移动窗体 文章分类 .Net 后端开发
-
将任务栏图标设置为只显示小图标
任务栏图标修改
任务栏 小图标 -
c#禁止通过拖动,双击标题栏改变窗体大小
最近写windows窗体程序,发现一个烦人的问题。窗体初始化时禁用了最大化按钮,并使之最大化。本希望窗体一直保
windows c# 标题栏 初始化 解决方法 -
winform无边框和标题栏窗体变化、移动实现
窗体的最大化、最小化、还原 winform窗体在无边框和标题栏的情况下,实现最大化会dowS
winform system c# 经验分享 标题栏 -
c# 拖动无标题栏窗体代碼(轉)
c# 拖动无标题栏窗体代碼........
sed hive html 其他 -
拦截双击标题栏、移动窗体的系统消息ide 移动窗体 标题栏 十进制 系统消息