6

I'd like to create a Form without title bar while keeping the border so I can still resize and snap it. Setting FormBorderStyle to None would work, but it destroys the border.

After searching Google for a bit, I encountered a method quite a few times, also here: Setting ControlBox to False as well as Text to an empty string seems to have worked on older versions of Windows, on Windows 10 however it looks like this:

Ugly rest of title bar

Note the ugly bar at the top, which I would like to get rid of. Every other solution I found - e.g. overriding WndProc - either simply did not work, or removed the border as well.

Edit: The white bar is in non-client area, it's what's left over from the title bar after removing the window buttons and title text.

9
  • Can confirm that. Ugly white non-client bar on top. It's acting as a border, to resize the height, why is it so big? Must be a bug. Commented Jan 2, 2019 at 16:00
  • 1
    Would you mind to try this hack, perhaps it's mentioned PaddedBorderWidth. Commented Jan 2, 2019 at 16:02
  • On this question stackoverflow.com/questions/2575216/… the second answer by user1306322 uses FormBorderStyle=None but draws the border back on and handles the necessary events to allow it to be resizable. Commented Jan 2, 2019 at 16:18
  • @Sinatr As far as I can tell, this modifies the registry, which is a global approach to this problem. However, I'd like my application to work on any Windows machine, without having to change the registry. Commented Jan 2, 2019 at 17:35
  • 1
    @Xam unfortunately, I did not :( Commented Jul 22, 2019 at 17:45

2 Answers 2

1

I only manged to do it with WndProc. But no bar at the top. Can be moved. Can be snap. WM_NCHITTEST is for resiz window. WM_NCCALCSIZE Is for removing the "ugly white line".

public Form1() { InitializeComponent(); var designSize = this.ClientSize; this.FormBorderStyle = FormBorderStyle.Sizable; this.Size = designSize; } const int WM_NCCALCSIZE = 0x83; const int WM_NCHITTEST = 0x0084; protected override void WndProc(ref Message message) { if (message.Msg == WM_NCHITTEST && message.Result == (IntPtr)0) { int GrabSize = 30; int x = unchecked((short)(long)message.LParam); int y = unchecked((short)((long)message.LParam >> 16)); var rect2 = new Rectangle(DesktopLocation.X + GrabSize, DesktopLocation.Y + GrabSize, ClientSize.Width - (GrabSize*2), ClientSize.Height - (GrabSize * 2)); if (!rect2.Contains(x, y)) { if (y > rect2.Bottom && x < rect2.Left) { message.Result = (IntPtr)16;// # HTBOTTOMLEFT } else if (y < rect2.Top && x > rect2.Right) { message.Result = (IntPtr)14;// # HTTOPRIGHT } else if (y > rect2.Bottom && x > rect2.Right) { message.Result = (IntPtr)17;// # HTBOTTOMRIGHT } else if (y < rect2.Top && x < rect2.Left) { message.Result = (IntPtr)13;// # HTTOPLEFT } else if (y > rect2.Bottom) { message.Result = (IntPtr)15; //# HTBOTTOM } else if (y < rect2.Top) { message.Result = (IntPtr)2; //# HTCAPTION for moving the window //message.Result = (IntPtr)12; //# HTTOP } else if (x < rect2.Left) { message.Result = (IntPtr)10; //# HTLEFT } else if (x > rect2.Right) { message.Result = (IntPtr)11;//# HTRIGHT } } else { message.Result = (IntPtr)(1); // # HTCLIENT In a client area. } return; } if (message.Msg == WM_NCCALCSIZE && message.WParam.ToInt32() == 1) { message.Result = (IntPtr)0; return; } base.WndProc(ref message); } 
Sign up to request clarification or add additional context in comments.

Comments

-1

Set BorderStyle to bsNone

then in the form's OnActivate, procedure, add the lines

 Canvas.Pen.Color:=clWindowFrame; Canvas.Rectangle(0,0,Width-2,Height-2) 

8 Comments

What is Canvas?
Canvas is a property, in this case, of your form. Look up TCanvas in Delphi help: "TCanvas provides an abstract drawing space for objects that must render their own images. "
What relation does Delphi have to C# and WinForms?
If you Google WinForms, you should find the answer. Personally, I'm not a Visual Studio user.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.