看了些网上的方法,拖动无标题栏窗体至少是拖动在窗体本身上的,我现在的情况是窗体被一个控件完全覆盖.我想通过拖动这个控件,从而拖动整个窗体.
请教高手,
要c#的winform方法,谢谢.
请教高手,
要c#的winform方法,谢谢.
解决方案 »
- asp.net安装源码有问题额。
- MSDN总是提示ms-help://MS.MSDNQTR.v80.en无效,如何解决?
- 哥哥们,帮小妹妹个忙哦~~~~~~~
- 可否在工具条上增加时间控件?急!!!!
- 大家都是用什么方法读取数据表中的某个纪录的值的?
- 5000分找Bug之二
- 用HttpWebResponse,HttpWebRequest 下载网页时遇到错误了,怎么办?
- 关于remoting服务端主动发送消息的问题
- 在datagrid控件中怎样得到当前行的坐标?急!!
- 初学线程,这样写对吗?(急!)
- 怎么把一个字符串中由固定字符(如!)分隔的字符串分拆开来?
- 高分求助!这种样子的表格标题怎么实现?
using System;
using System.Drawing;
using System.Windows.Forms;
public class TestForm : Form
{
private const int WM_NCLBUTTONDOWN = 0x00A1;
private const int WM_NCHITTEST = 0x84;
private const int HT_CAPTION = 0x2;
private const int HT_CLIENT = 0x1; Label t = new Label();
TestForm()
{
t.Size = this.Size;
t.Text = "hello world";
t.Location = new Point(0,0);
t.BackColor = Color.Red;
t.MouseDown += new MouseEventHandler(this.Label_MouseDown);
Controls.Add(t);
}
private void Label_MouseDown(object sender, MouseEventArgs e)
{
t.Capture = false;
Message msg=Message.Create(Handle, WM_NCLBUTTONDOWN, (IntPtr)HT_CAPTION, IntPtr.Zero);
WndProc(ref msg);
} static void Main()
{
Application.Run(new TestForm());
}
}
http://blog.csdn.net/chengking/archive/2005/10/07/496739.aspx
我再加两个方法:
1.
#region 窗体拖动
const int WM_NCHITTEST = 0x0084;
const int HTCLIENT = 0x0001;
const int HTCAPTION = 0x0002;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result==(IntPtr)HTCLIENT)
m.Result=(IntPtr)HTCAPTION;
break;
default:
base.WndProc(ref m);
break;
} }
#endregion
-----------------------------------------------------------
2.
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd,int wMsg,int wParam,int lParam);
public const int WM_SYSCOMMAND=0x0112;
public const int SC_MOVE=0xF010;
public const int HTCAPTION=0x0002;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);
}
-----------------------------------------------------------------
当然你也可用API的Capture,ReleaseCapture