我正在尝试使用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_MouseMove
和StatusStrip_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仍然无效。我错过了什么吗?