Remove winforms and WindowState borders Maximized without full screen mode

I have the following problem and I have not found a solution.

I want to implement Winform without a top bar and, if possible, without borders. I tried several things without success, the following would do the trick perfectly:

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

getting the following result:

Everything works perfectly! But when I do it in a maximized state

The little problem is that I or the user are triggering the maximization condition, because this will make the form entered in FULLSCREEN mode! and I do not know how to prevent this:

See? You do not see the Windows taskbar!

Cm? You do not see the Windows taskbar! I use

 WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want ! 

Appreciate your help!

+7
c # winforms
source share
6 answers

Try setting a dynamic size, this may help you.

Do not use WindowState = FormWindowState.Maximized; Try this code in the download form.

 var rectangle = ScreenRectangle(); Size = new Size(rectangle.Width - 100, rectangle.Height - 100); Location = new Point(50, 50); // here 100 is pixel used to reserve from edges, // you can set lower value according to your requirements 

For full size

 var rectangle = ScreenRectangle(); Size = new Size(rectangle.Width, rectangle.Height); Location = new Point(0, 0); 

Rectangle Method:

 public Rectangle ScreenRectangle() { return Screen.FromControl(this).Bounds; } 
+6
source share

Good! Thanks to all your answers, I finally solved the following two methods:

  private void MaximizeWindow() { var rectangle = Screen.FromControl(this).Bounds; this.FormBorderStyle = FormBorderStyle.None; Size = new Size(rectangle.Width, rectangle.Height); Location = new Point(0, 0); Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea; this.Size = new Size(workingRectangle.Width, workingRectangle.Height); } private void ResizableWindow() { this.ControlBox = false; this.FormBorderStyle = FormBorderStyle.SizableToolWindow; } 

Thanks to X-TECH and LuΓ―s, this was decided!

The maximum state and taskbar are still there!

+5
source share

If you want to take control of form maximization, do it like this:

  public class MyForm { protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_MAXIMIZE = 0xF030; // When form is going to be maximized if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MAXIMIZE)) { m.Msg = 0; // <- we don't want a standard maximization //TODO: tell Windows here what to do when user want to maximize the form // Just a sample (pseudo maximization) Location = new Point(0, 0); Size = new Size(Screen.GetWorkingArea(this).Width, Screen.GetWorkingArea(this).Height); } base.WndProc(ref m); } ... } 
+3
source share

Remove the border

 this.FormBorderStyle = FormBorderStyle.None; 

I think this works by clicking the maximize button

 // Add following namespaces using System.Windows.Forms; using System.Drawing; // Retrieve the working rectangle from the Screen class using the PrimaryScreen and the // WorkingArea properties. Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea; // Set the size of the form slightly less than size of working rectangle. this.Size = new Size(workingRectangle.Width, workingRectangle.Height); 

Sources: MSDN system.windows.forms.screen.primaryscreen and Remove title bar in Windows Forms

+1
source share

hi, you can do this with only two instructions: this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size; this.WindowState = FormWindowState.Maximized;

0
source share
 this.Text = string.Empty; this.ControlBox = false; this.FormBorderStyle = FormBorderStyle.SizableToolWindow; this.Left = this.Top = 0; this.Height = Screen.GetWorkingArea(this).Height; this.Width = Screen.GetWorkingArea(this).Width; 

GetWorkingArea . Gets the working area of ​​the display. The workspace is the area of ​​the display desktop, excluding taskbars , docking windows, and docking toolbars. MSDN

-2
source share

All Articles