C# - How to make a StatusStrip resize a borderless Form

▼魔方 西西 提交于 2019-12-11 10:36:53

问题


I am trying to resize a borderless form with a StatusStrip (I'm using a tool strip for many reasons). I have successfully moved a form with a MenuStrip, but never resized, so I do have a little understanding on sending messages and EventHandling. However, the StatusStrip doesn't move when clicked. Below is what I have so far.

Custom StatusStrip Class:

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);
        }
    }
}

The designer lets me drag-and-drop this element because it recognizes it as a control like I want it to...

Form Class:

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();
        }
    }
}

I even manually added StatusStrip_MouseMove and StatusStrip_MouseDown to MyForm.Designer.cs EventHandling through:

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

But the StatusStrip Still does nothing. Am I missing something?

来源:https://stackoverflow.com/questions/29064674/c-sharp-how-to-make-a-statusstrip-resize-a-borderless-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!