1

我正在尝试使用 StatusStrip 调整无边框表单的大小(出于多种原因,我正在使用工具条)。我已经成功移动了一个带有 MenuStrip 的表单,但从未调整大小,所以我对发送消息和 EventHandling 有一点了解。但是,单击时 StatusStrip 不会移动。以下是我到目前为止所拥有的。

自定义 StatusStrip 类:

public class PassThroughStatusStrip : StatusStrip{
    protected override void WndProc(ref Message m){
        const int WM_NCHITTEST = 0x0084;
        const int HTTRANSPARENT = (-1);

        if (m.Msg == WM_NCHITTEST){
            m.Result = (IntPtr)HTTRANSPARENT;
        }else{
            base.WndProc(ref m);
        }
    }
}

设计器允许我拖放这个元素,因为它可以将它识别为一个控件,就像我想要的那样......

表格类:

public partial class MyForm : Form
{   
    private const int HTCAPTION = 0x2;
    public const int WM_NCLBUTTONDOWN = 0xA1;

    [DllImportAttribute("user32.dll")]
    private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [DllImportAttribute("user32.dll")]
    private static extern bool ReleaseCapture();

    public MyForm()
    {
        InitializeComponent();
    }
    private void StatusStrip_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left){
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
        }
    }
    private void StatusStrip_MouseMove(object sender, MouseEventArgs e)
    {
        if (!Focused)
        {
            Focus();
        }
    }
}

我什至通过以下方式手动添加StatusStrip_MouseMoveStatusStrip_MouseDown到 MyForm.Designer.cs EventHandling:

this.StatusStrip.MouseDown += new System.Windows.Forms.MouseEventHandler(this.StatusStrip_MouseDown);
this.StatusStrip.MouseMove += new System.Windows.Forms.MouseEventHandler(this.StatusStrip_MouseMove);

但是 StatusStrip 仍然什么都不做。我错过了什么吗?

4

0 回答 0