调用user32.dll轻松移动窗体上任何控件

//引用命名空间 System.Runtime.InteropServices
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);

先添加上边语句,然后编写控件MouseMove事件的处理程序(下边代码移动PictureBox控件):

pictureBox1.MouseMove += delegate(object sender, MouseEventArgs e)
{
    PictureBox picbox = (PictureBox)sender;
    picbox.Capture = false;
    SendMessage(picbox.Handle, 0x0112, 0xF012, 0);
};


上一篇: Form2中访问Form1
下一篇: C#控件的拖动和缩放技术全解
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 0 | 引用: 0 | 查看次数: 4463
发表评论
登录后再发表评论!