8

I was wondering how to hide the titlebar of a form but keep the original border, like e.g Dropbox does: screenshot

Thanks in advance!

3 Answers 3

8

Set FormBorderStyle to FormBorderStyle.Sizable or FormBorderStyle.SizableToolWindow and set Text to an empty string, and ControlBox to false

Note that FixedToolWindow won't work, it will remove the border. If you don't want it to be sizable, use SizableToolWindow and add this to the form's codebehind (adding both languages since you don't specify and tagged the question with both):

In vb.net:

Protected Overrides Sub WndProc(ByRef message As Message) If message.Msg = &H84 Then ' WM_NCHITTEST message.Result = CType(1, IntPtr) Return End If MyBase.WndProc(message) End Sub 

In C#:

protected override void WndProc(ref Message message) { if (message.Msg == 0x0084) // WM_NCHITTEST message.Result = (IntPtr)1; else base.WndProc(ref message); } 
Sign up to request clarification or add additional context in comments.

5 Comments

This hides the border of the form completely. It's the same as setting FormBorderStyle to FormBorderStyle.None.
@Brennced no, it doesn't, I just made a test, and it shows the border, exactly like Dropbox's window
Nevermind. I forgot to remove some code that hides the form border. Thank you for your quick answer.
Amazing! I've been wanting this too!
@HansPassant good catch. I see you did update already. Thanks for that!
1

Here is a simple way:

this.ControlBox = false; this.Text = string.Empty; 

If the Form is designed to be a pop-up dialog, you might want to add the following line:

this.ShowInTaskBar = false; 

That keeps the Form from appearing in the taskbar.

Comments

-1
// 3rd option (C#) protected override CreateParams CreateParams { get { int WS_DLGFRAME = 0x400000; CreateParams result = base.CreateParams; result.Style &= ~WS_DLGFRAME; return result; } } 

2 Comments

While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.
@IgorF. As it says, it's a 3rd option. Period. I was googling with the memory that there is a property one could override and change window creation, but I couldn't find it here. Of course I prefer Smith's answer. Last thing I would do in such a case is override WndProc.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.