看了些网上的方法,拖动无标题栏窗体至少是拖动在窗体本身上的,我现在的情况是窗体被一个控件完全覆盖.我想通过拖动这个控件,从而拖动整个窗体.
请教高手,
要c#的winform方法,谢谢.

解决方案 »

  1.   

    what kind of control, you could try out the following example
    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());  
       }  
    }  
      

  2.   

    参考:
    http://blog.csdn.net/chengking/archive/2005/10/07/496739.aspx
      

  3.   

    有三种方法可以实现,上面说的在鼠标事件中加入代码,确定鼠标位置是可以的
    我再加两个方法:
    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