(更新时间)2021年5月21日 仓库温控系统(Winform) 19 窗体拖动功能实现
【摘要】
Point point = new Point();
bool isMove = false;
private void panelTop_MouseDown(object sender, MouseEv...
Point point = new Point();
bool isMove = false;
private void panelTop_MouseDown(object sender, MouseEventArgs e)
{
point = e.Location;//按住的点
isMove = true;
}
private void panelTop_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left&&isMove)
{
Point pointNew = e.Location;//按住的点拖动到的位置
Point fPointNew = new Point(pointNew.X - point.X, pointNew.Y - point.Y);//相对于原来起点的距离点的描述
this.Location += new Size(fPointNew);
}
}
const int WM_NCHITTEST = 0x0084;// 移动鼠标
const int HTLEFT = 10;
const int HTRIGHT = 11;
const int HTTOP = 12;
const int HTTOPLEFT = 13;
const int HTTOPRIGHT = 14;
const int HTBOTTOM = 15;
const int HTBOTTOMLEFT = 0x10;
const int HTBOTTOMRIGHT = 17;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
if (vPoint.X <= 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPLEFT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOMLEFT;
else m.Result = (IntPtr)HTLEFT;
else if (vPoint.X >= ClientSize.Width - 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOMRIGHT;
else m.Result = (IntPtr)HTRIGHT;
else if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOP;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOM;
break;
}
}
/// <summary>
/// 面板中的页面尺寸与面板的尺寸同步---面板中Form页自适应处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panelPage_SizeChanged(object sender, EventArgs e)
{
foreach(Control c in panelPage.Controls)
{
Form f = c as Form;
f.WindowState = FormWindowState.Normal;
f.SuspendLayout();
f.Size = panelPage.Size;
//DataGridView 闪烁--- 先挂起 ,,,再恢复
f.ResumeLayout();
f.WindowState = FormWindowState.Maximized;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。
原文链接:codeboy.blog.csdn.net/article/details/117118442
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)