将标题栏隐藏后,如何使用鼠标拖动窗体?

jinus 2003-08-30 04:14:02
就是在客户区拖动窗口,谢谢!
...全文
57 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinus 2003-08-30
  • 打赏
  • 举报
回复
谢谢各位, chenxy2002((HomeMan) 的
p=this.PointToScreen(p);
正是我想要得,其余大侠的方法太高深了,待我研究研究。
雪狼1234567 2003-08-30
  • 打赏
  • 举报
回复
重载消息处理函数
当程序受到(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
rouser 2003-08-30
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/TopicView1.asp?id=2205855
chenxy2002 2003-08-30
  • 打赏
  • 举报
回复
p定义为全局的Point对象
chenxy2002 2003-08-30
  • 打赏
  • 举报
回复
private void frmLogin_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
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;
}
}
TheAres 2003-08-30
  • 打赏
  • 举报
回复
可以在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);
}
树猫 2003-08-30
  • 打赏
  • 举报
回复
写窗体的鼠标事件

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧