从网上看到了一个窗体拖动事件,超级简洁,至少现在这个阶段我是看起来有困难的
有兴趣的哥们们可以讨论下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
private const int WM_NCHITTEST = 0x84;//这几行真够晕的,貌似调用了基本函数饿
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
return;
break;
}
base.WndProc(ref m);
}
}
}
我试过了,可以运行,就是貌似最后那个break有点问题,看不懂...嘿嘿 还得继续努力啊!
c#窗体事件
最新推荐文章于 2025-03-22 09:00:00 发布
本文介绍了一个简洁的窗体拖动事件实现方法,通过重写WndProc方法并利用WM_NCHITTEST消息,使得窗体的任意位置均可响应拖动操作。此方法涉及C#编程和Windows窗体应用。
808

被折叠的 条评论
为什么被折叠?



