1

I want my Windows Forms form to keep the window border, while having no title bar and being non-resizable (fixed) (similarly to window previews, when one hovers mouse over button on the taskbar):

enter image description here

Setting ControlBox to false and Text to "" removes the title bar and keeps the border as I want to, but the border is visible only if the form is sizeable. When I set the FormBorderStyle to one of the Fixed* styles, the border disappears:

enter image description here

How may I achieve the described behavior?

Spook
  • 25,318
  • 18
  • 90
  • 167
  • For my please wait dialog, I just put a panel docked around my form (behind controls) and used the panel border – Sayse Jul 31 '13 at 20:31
  • "Fixed" is not a valid setting for the FormBorderStyle property. Document your question better. Include at least include a screen shot of the running window, the Windows version and a shot of a they way you want it to look. – Hans Passant Jul 31 '13 at 20:40
  • @HansPassant People, who answered my question seem to understand perfectly what I am asking about. I included the screenshots, though. – Spook Aug 01 '13 at 07:50

2 Answers2

1

You can pinvoke SetWindowsLong and adjust window styles:

// run in LINQpad
private const int GWL_STYLE = -16;
private const int WS_SIZEBOX = 0x040000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
void Main()
{
    var form = new Form();
    form.ControlBox = false;
    form.FormBorderStyle = FormBorderStyle.FixedDialog;
    form.Show();
    SetWindowLong(form.Handle, GWL_STYLE, GetWindowLong(form.Handle, GWL_STYLE) | WS_SIZEBOX);
}

After that you would have to prevent resizing manually though.

Community
  • 1
  • 1
m0sa
  • 10,712
  • 4
  • 44
  • 91
  • Now he's got two problems, these declarations are wrong for 64-bit code. Overriding the CreateParams property is the correct way. – Hans Passant Jul 31 '13 at 23:42
0

I just played around with a project of mine and set FormBorderStyle to FixedSingle through the Design view, and the window seems to keep the border for Windows 8. I initially had text in the title, which was forcing the border to render. I removed the text and the border no longer rendered, so as a hacky solution I just input an empty string, by hitting backspace a few times. This made the border show up and remain fixed.

ZeroPhase
  • 649
  • 4
  • 21