1

It should look like the little box that appears when you click the Action Center, Power, Network, or Sound icon in the tray. It needs to have that glass border without the title bar.

enter image description here

It also needs to be a fixed size and not resizable. Thanks to anyone who can help! :)

Phoenix Logan
  • 1,238
  • 3
  • 19
  • 31
  • A few seconds of googling should give you the answer. Disable the Maximise, Minimse and Control boxes, set the title to empty string and set the form `FormBorderStyle` to `Fixed3D` – Basic Jan 12 '13 at 01:55
  • This doesn't give me a glass-like border... It does work when I set the border to Sizable but it has to be fixed size. – Phoenix Logan Jan 12 '13 at 02:03
  • possible duplicate of [Create a System-tray styled box in Winforms (C#)](http://stackoverflow.com/questions/2169006/create-a-system-tray-styled-box-in-winforms-c) – Factor Mystic Jan 12 '13 at 03:15
  • @FactorMystic That is not an exact duplicate. The accepted answer in that question is resizable, which is not what Phoenix is looking for. – John Koerner Jan 12 '13 at 03:19
  • No but to be fair the difference between the 2 is a single property... – Basic Jan 12 '13 at 03:20
  • @Basic As you can see from my answer it is a little more than a single property to get the correct look and feel. – John Koerner Jan 12 '13 at 13:09

1 Answers1

3

You need to set the ControlBox to false, clear the title text, and set the border style. Since you stated you want the sizable border, but not allow it to be resized, you can set the min and max size as well. Finally to prevent the mouse cursor from showing the resize cursor, we override the WM_NCHITTEST result if they are on one of the borders:

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;
        }
    }
}
John Koerner
  • 37,428
  • 8
  • 84
  • 134