移动没有标题的窗体?

gggitxai 2003-05-25 07:10:20
请问怎样才能移动没有标题的窗体?列如在VB中可以调用API来完成,请问C#中怎样实现?
...全文
38 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mullen 2003-05-25
  • 打赏
  • 举报
回复
我以前用vb的时候曾经是直接通过鼠标的位置来判断移动的,效果很自然,我想你可以考虑。
coollzh 2003-05-25
  • 打赏
  • 举报
回复
protected override void WndProc(ref Message msg)
{

base.WndProc(ref msg);
if (msg.Msg == 0x0084)
{
if(msg.Result == new IntPtr(1))
{
msg.Result = new IntPtr(2);
return;
}

}


}
chinchy 2003-05-25
  • 打赏
  • 举报
回复
可以在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);
}

110,546

社区成员

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

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

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