How to make WinForms application fully included?

I have a WinForms application that I am trying to do in full screen (something like what VS does in full screen).

I am currently setting FormBorderStyle to None and WindowState to Maximized , which gives me a bit more space, but it does not cover the taskbar if it is visible.

What do I need to do to use this space?

As for bonus points, can I do something to make autohide MenuStrip also abandon this space?

+98
c # winforms
Feb 02 '09 at 22:10
source share
8 answers

The basic trick is the following trick (hiding the taskbar)

 private void Form1_Load(object sender, EventArgs e) { this.TopMost = true; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; } 

But, interestingly, if you change these last two lines, the taskbar will remain visible. I think that the sequence of these actions will be difficult to control using the properties window.

+138
Feb 03 '09 at 15:30
source share

Proven and easy solution

I searched for the answer to this question in SO and some other sites, but one gave an answer, it was very difficult for me, and some other answers just didn’t work correctly, so after a lot of testing the code, I solved this puzzle.

Note. I am using Windows 8 and my taskbar is not in auto-hide mode.

I found that setting WindowState to Normal before making any changes will stop the error with the taskbar closed.

The code

I created this class, which has two methods, the first goes into "full screen mode" and the second leaves "full screen mode". Thus, you just need to create an object of this class and pass the form you want to set full screen as an argument to EnterFullScreenMode or LeaveFullScreenMode:

 class FullScreen { public void EnterFullScreenMode(Form targetForm) { targetForm.WindowState = FormWindowState.Normal; targetForm.FormBorderStyle = FormBorderStyle.None; targetForm.WindowState = FormWindowState.Maximized; } public void LeaveFullScreenMode(Form targetForm) { targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; targetForm.WindowState = FormWindowState.Normal; } } 

Usage example

  private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e) { FullScreen fullScreen = new FullScreen(); if (fullScreenMode == FullScreenMode.No) // FullScreenMode is an enum { fullScreen.EnterFullScreenMode(this); fullScreenMode = FullScreenMode.Yes; } else { fullScreen.LeaveFullScreenMode(this); fullScreenMode = FullScreenMode.No; } } 

I put the same answer to another question, which I'm not sure if this is a duplicate or not. (Link to another question: How to display a Windows form in full screen on the taskbar? )

+18
May 26 '13 at 22:59
source share

And for the menustrip question try setting

 MenuStrip1.Parent = Nothing 

when in full screen it should disappear.

And when you exit full-screen mode, reset menustrip1.parent to form again, and menustrip will be normal again.

+6
Feb 02 '09 at 23:28
source share

You can use the following code to fit your system screen and the taskbar is visible.

  private void Form1_Load(object sender, EventArgs e) { // hide max,min and close button at top right of Window this.FormBorderStyle = FormBorderStyle.None; // fill the screen this.Bounds = Screen.PrimaryScreen.Bounds; } 

No need to use:

  this.TopMost = true; 

This line prevents alt+tab switching to another application. ("TopMost" means that the window stays on top of other windows unless they are marked as "TopMost.")

+5
Feb 12 '13 at 12:43
source share

I recently made a Mediaplayer application and I used API calls to make sure that the taskbar was hidden when the program started in full screen mode, and then restored the task bar when the program was not in full screen mode or had no focus or was closed.

 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer Sub HideTrayBar() Try Dim tWnd As Integer = 0 Dim bWnd As Integer = 0 tWnd = FindWindow("Shell_TrayWnd", vbNullString) bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString) ShowWindow(tWnd, 0) ShowWindow(bWnd, 0) Catch ex As Exception 'Error hiding the taskbar, do what you want here.. End Try End Sub Sub ShowTraybar() Try Dim tWnd As Integer = 0 Dim bWnd As Integer = 0 tWnd = FindWindow("Shell_TrayWnd", vbNullString) bWnd = FindWindowEx(tWnd, bWnd, "BUTTON", vbNullString) ShowWindow(bWnd, 1) ShowWindow(tWnd, 1) Catch ex As Exception 'Error showing the taskbar, do what you want here.. End Try End Sub 
+3
Feb 02 '09 at 23:19
source share

You need to set the top window.

+2
Feb 02 '09 at 22:12
source share

I do not know if it will work on .NET 2.0, but it worked on .NET 4.5.2. Here is the code:

 using System; using System.Drawing; using System.Windows.Forms; public partial class Your_Form_Name : Form { public Your_Form_Name() { InitializeComponent(); } // CODE STARTS HERE private System.Drawing.Size oldsize = new System.Drawing.Size(300, 300); private System.Drawing.Point oldlocation = new System.Drawing.Point(0, 0); private System.Windows.Forms.FormWindowState oldstate = System.Windows.Forms.FormWindowState.Normal; private System.Windows.Forms.FormBorderStyle oldstyle = System.Windows.Forms.FormBorderStyle.Sizable; private bool fullscreen = false; /// <summary> /// Goes to fullscreen or the old state. /// </summary> private void UpgradeFullscreen() { if (!fullscreen) { oldsize = this.Size; oldstate = this.WindowState; oldstyle = this.FormBorderStyle; oldlocation = this.Location; this.WindowState = System.Windows.Forms.FormWindowState.Normal; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds; fullscreen = true; } else { this.Location = oldlocation; this.WindowState = oldstate; this.FormBorderStyle = oldstyle; this.Size = oldsize; fullscreen = false; } } // CODE ENDS HERE } 

Using:

 UpgradeFullscreen(); // Goes to fullscreen UpgradeFullscreen(); // Goes back to normal state // You don't need arguments. 

Note: You MUST put it in your Form class (Example: partial class Form1 : Form { /* Code goes here */ } ) or it will not work, because if you do not put it in any form, this code will throw an exception.

+1
Oct 28 '16 at 14:12
source share

On the Form Move Event, add this:

 private void Frm_Move (object sender, EventArgs e) { Top = 0; Left = 0; Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); } 
0
May 16 '19 at 19:28
source share



All Articles