1

当您单击托盘中的操作中心、电源、网络或声音图标时,它应该看起来像出现的小框。它需要有没有标题栏的玻璃边框。

在此处输入图像描述

它还需要是固定大小且不可调整大小。感谢任何能提供帮助的人!:)

4

1 回答 1

3

需要将ControlBox设置为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;
        }
    }
}
于 2013-01-12T02:00:48.313 回答