0

I want to remove the titlebar of winform,like electron frameless window. By adding the following code, the titlebar is removed, but there is a blank bar at the top of the window. How can I remove this blank bar?

enter image description here

private void InitializeComponent(){
            ControlBox = false;
}

enter image description here

Electron frameless window can completely remove the titlebar,

Jyu
  • 1
  • 1

1 Answers1

0

The ControlBox doesn't remove the title bar from the window. Instead, you need to use the following code:

public Form1()
{
    InitializeComponent();
    FormBorderStyle = FormBorderStyle.None;
}

The border style of the form determines how the outer edge of the form appears. In addition to changing the border display for a form, certain border styles prevent the form from being sized. For example, the FormBorderStyle.FixedDialog border style changes the border of the form to that of a dialog box and prevents the form from being resized. The border style can also affect the size or availability of the caption bar section of a form.

If that solution doesn't suit your needs you may consider using Windows API functions such as SetWindowLong which changes an attribute of the specified window. See Opening a window that has no title bar with Win32 for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • If so, the size of the form cannot be changed, and the shadow outside the form is lost. – Jyu Feb 25 '23 at 14:29
  • In that case you need to use Windows API setting up a windows style, for example, take a look at the `SetWindowLong` function. – Eugene Astafiev Feb 25 '23 at 14:35
  • Use `SetWindowLong(this.Handle, GWL_STYLE, 0); ` ,Same as `FormBorderStyle = FormBorderStyle.None;` – Jyu Feb 25 '23 at 16:18