它应该看起来像单击任务栏中的“操作中心”、“电源”、“网络”或“声音”图标时出现的小框。它需要有没有标题栏的玻璃边框。
它还需要是一个固定的大小,而不是可调整的。感谢所有能帮忙的人!:)
最佳答案
您需要将控制框设置为false,清除标题文本,并设置边框样式。既然您声明希望调整边框的大小,但不允许调整其大小,那么也可以设置最小和最大大小。最后,为了防止鼠标光标显示“调整大小”光标,如果结果位于其中一个边框上,我们将覆盖WM_NCHITTEST结果:
private void Form1_Load(object sender, EventArgs e)
{
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.MinimumSize = this.MaximumSize = this.Size;
this.Text = "";
}
const int WM_NCHITTEST = 0x0084;
const int HTBOTTOM = 15;
const int HTBOTTOMLEFT = 16;
const int HTBOTTOMRIGHT = 17;
const int HTLEFT = 10;
const int HTRIGHT = 11;
const int HTTOPLEFT = 13;
const int HTTOPRIGHT = 14;
const int HTTOP = 12;
const int HTCLIENT = 1;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
{
Console.WriteLine(m.Result.ToString());
switch (m.Result.ToInt32())
{
case HTBOTTOM:
case HTBOTTOMLEFT:
case HTBOTTOMRIGHT:
case HTLEFT:
case HTRIGHT:
case HTTOPLEFT:
case HTTOPRIGHT:
case HTTOP:
m.Result =(IntPtr) HTCLIENT;
break;
}
}
}