C# 怎么拖动panel?
答案:2 悬赏:80 手机版
解决时间 2021-11-13 14:23
- 提问者网友:我们很暧昧
- 2021-11-12 19:11
C# 怎么拖动panel?
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-11-12 19:39
private void panel2_MouseDown(object sender, MouseEventArgs e) //鼠标MouseDown的事件 { if (e.Button == MouseButtons.Left) { this.Opoint.X = e.X; this.Opoint.Y = e.Y; } } private void panel2_MouseMove(object sender, MouseEventArgs e) //鼠标MouseMove的事件 { if (e.Button == MouseButtons.Left) { this.panel2.Left = this.panel2.Left + e.X - this.Opoint.X; this.panel2.Top = this.panel2.Top + e.Y - this.Opoint.Y; } } 你试试这个 希望对你有帮助
全部回答
- 1楼网友:举杯邀酒敬孤独
- 2021-11-12 20:57
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern void ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern void SendMessage(int hwnd, int wMsg, int wParam, int lParam);
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage((int)移动的对象.Handle, 0xA1, 2, 0);
//是窗体自身就是
//SendMessage((int)this.Handle, 0xA1, 2, 0);
//panel就是SendMessage((int)panel1.Handle, 0xA1, 2, 0);
}
}
public static extern void ReleaseCapture();
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern void SendMessage(int hwnd, int wMsg, int wParam, int lParam);
把上面语句加载窗体类文件中,然后在拖拽的控件上加事件,比如我是一个panel
private void panelForm_MouseDown(object sender, MouseEventArgs e){
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage((int)移动的对象.Handle, 0xA1, 2, 0);
//是窗体自身就是
//SendMessage((int)this.Handle, 0xA1, 2, 0);
//panel就是SendMessage((int)panel1.Handle, 0xA1, 2, 0);
}
}
这种才是windows标准的拖拽事件,下面那位,拖动的时候窗体会闪烁不停,一直在渲染背景
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯