可以在mouse_down事件中发送WM_NCLBUTTONDOWN来实现你要的效果,可以参考下面的代码.using System.Runtime.InteropServices;
............
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;[DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture();private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
............
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;[DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture();private void Form2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
解决方案 »
- 如何把图片先加载到内存中
- C#实现HTTP的POST方法的通信问题
- webBrowser控件链接问题
- DataGridView下标的问题(超级不理解)
- 急!请问智能设备CAB项目部署时可以把NETCFv35.wce.armv4.cab集成进去吗
- 谁有用DGI+画销售曲线图的原码参考一下??
- 求解C#中类与派生类实例化后的内存结构图
- 怎样在C#中使用C++写的类,敬请高手赐教!
- {高难度}在ProtertyGrid中,如何让对象的属性名显示为中文!!!!!
- 分太多,散之!
- 【高分】在Windows Form的DataGrid中,使得符合某些条件的列的代码显示为特殊颜色,应该如何实现?
- 因为界面的要求,要使用一个没有边框的Form,但是这样就没有办法拖动窗口了. 着急等待中...
{
this.Cursor=Cursors.SizeAll;
p= new Point(e.X,e.Y);
p=this.PointToScreen(p);
} private void frmLogin_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Cursor= Cursors.Default;
} private void frmLogin_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
Point tp= new Point(e.X,e.Y);
tp= this.PointToScreen(tp);
this.Top += tp.Y -p.Y;
this.Left += tp.X-p.X;
this.p=tp;
}
}
当程序受到(WM_NCHITTEST)的时候,改变消息的处理结果返回给系统
就是欺骗windows让他以为鼠标点到了表题栏上,这行就可以托动了protected override void WndProc(ref Message msg)
{
if (msg.Msg == 0x0084) // WM_NCHITTEST
msg.Result = (IntPtr) 2; // HTCAPTION
else
base.WndProc(ref msg);
}
来源:
http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&threadm=_D3p8.73158%24in3.22907252%40typhoon.nyc.rr.com&rnum=1&prev=/groups%3Fq%3D(msg.Msg%2B%253D%253D%2B0x0084%26hl%3Dzh-CN%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D_D3p8.73158%2524in3.22907252%2540typhoon.nyc.rr.com%26rnum%3D1
p=this.PointToScreen(p);
正是我想要得,其余大侠的方法太高深了,待我研究研究。