Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a Windows Form in full screen on top of the taskbar? [duplicate]

I have a .net windows application that needs to run in full screen. When the application starts however the taskbar is shown on top of the main form and it only disappears when activating the form by clicking on it or using ALT-TAB. The form's current properties are as follow:

  • WindowState=FormWindowState.Normal
  • TopMost=Normal
  • Size=1024,768 (this is the screen resolution of the machines it's going to be running on)
  • FormBorderStyle = None

I've tried adding the followings on form load but none worked for me:

  • this.Focus(); (after giving the focus this.Focus property is always false)
  • this.BringToFront();
  • this.TopMost = true; (this however would not be ideal in my scenario)
  • this.Bounds = Screen.PrimaryScreen.Bounds;
  • this.Bounds = Screen.PrimaryScreen.Bounds;

Is there a way to do it within .NET or would I have to invoke native windows methods and if so a code snippet would very much be appreciated.

many thanks

like image 967
myquestionoftheday Avatar asked Feb 16 '10 10:02

myquestionoftheday


People also ask

How do I fit windows form to any resolution?

simply set Autoscroll = true for ur windows form..

How do I maximize a form in Visual Studio?

Set the WindowState property of your form to Maximized . That will cause your form to be maximumized when it's opened. In addition, the FormBorderStyle can be set to FormBorderStyle. None to remove the border as well, for a more true maximized feeling, no borders added.


2 Answers

Use:

FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; 

And then your form is placed over the taskbar.

like image 194
TcKs Avatar answered Sep 24 '22 06:09

TcKs


I've tried so many solutions, some of them works on Windows XP and all of them did NOT work on Windows 7. After all I write a simple method to do so.

private void GoFullscreen(bool fullscreen)     {         if (fullscreen)         {             this.WindowState = FormWindowState.Normal;             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;             this.Bounds = Screen.PrimaryScreen.Bounds;         }         else         {             this.WindowState = FormWindowState.Maximized;             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;         }     } 

the order of code is important and will not work if you change the place of WindwosState and FormBorderStyle.

One of the advantages of this method is leaving the TOPMOST on false that allow other forms to come over the main form.

It absolutely solved my problem.

like image 25
mammadalius Avatar answered Sep 22 '22 06:09

mammadalius