在vs2005  C#中,如何实现以下功能:
双击窗体标题栏,使整个窗体缩成只剩下标题栏;
再双击一遍则恢复。

解决方案 »

  1.   

    this.Size=  new Size(this.Width,System.Windows.Forms.SystemInformation.ToolWindowCaptionHeight);
      

  2.   

    双击时执行//记录双击前的height=this.Height
    height=this.Height;
    this.Height=0;
    单击时执行this.Height=height;
      

  3.   

    双击窗体标题栏由操作系统控制,所以你只能听Resize事件,判断WindowStatus,然后设置窗体的大小。
      

  4.   

    int WM_NCLBUTTONDBLCLK = 0xA3;        int h = 100;
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == WM_NCLBUTTONDBLCLK)
                {
                    if (this.Height < 30)
                    {
                        this.Height = h;
                    }
                    else
                    {
                        h = this.Height;
                        this.Height = 0;
                    }                
                    return;
                    
                }
                base.WndProc(ref m);
            }
      

  5.   

    关键是如何捕获双击标题的事件
    当双击标题,窗体会收到WM_NCLBUTTONDBLCLK消息,处理之即可
    参考如下代码:
    int oldHeight = 0;
    protected override void WndProc(ref Message m)
    {
        const int WM_NCLBUTTONDBLCLK = 0x00A3;
        switch (m.Msg)
        {
            case WM_NCLBUTTONDBLCLK:
                if (oldHeight <= 0)
                {
                    oldHeight = ClientSize.Height;
                    ClientSize = new Size(ClientSize.Width, 0);
                }
                else
                {
                    ClientSize = new Size(ClientSize.Width, oldHeight);
                    oldHeight = 0;
                }
                return;
        }
        base.WndProc(ref m);
    }