Many WinForms applications require true full-screen mode for optimal user experience and visual immersion. This guide details how to achieve this, along with advanced techniques for maximizing screen real estate.
Simply setting FormBorderStyle
to None
and WindowState
to Maximized
expands the application's display area. However, the taskbar remains, reducing usable space. To achieve a truly full-screen experience, additional steps are necessary.
The following code snippet provides the solution:
<code class="language-csharp">private void Form1_Load(object sender, EventArgs e) { // Bring the form to the foreground this.TopMost = true; // Remove the form's border this.FormBorderStyle = FormBorderStyle.None; // Maximize the form to fill the entire screen this.WindowState = FormWindowState.Maximized; }</code>
TopMost
ensures the form remains above other windows. Setting FormBorderStyle
to None
removes the form's borders, allowing it to extend to the screen's edges. Maximized
then expands the form to its maximum size.
To further optimize screen space, consider hiding the MenuStrip
when not actively used. This can be accomplished with the following code:
<code class="language-csharp">// Adjust to match your MenuStrip's height private const int MENU_STRIP_HEIGHT = 24; private void Form1_SizeChanged(object sender, EventArgs e) { // Hide the MenuStrip when maximized if (this.WindowState == FormWindowState.Maximized) { this.MenuStrip1.Visible = false; // Reduce form height to compensate for the hidden MenuStrip this.Height -= MENU_STRIP_HEIGHT; } // Show the MenuStrip when not maximized else { this.MenuStrip1.Visible = true; // Restore form height to include the MenuStrip this.Height += MENU_STRIP_HEIGHT; } }</code>
This utilizes the SizeChanged
event to detect form resizing (including maximization). When maximized, the MenuStrip
is hidden, and the form's height is adjusted. The reverse occurs when the form is not maximized.
The above is the detailed content of How Can I Make My WinForms Application Truly Full Screen?. For more information, please follow other related articles on the PHP Chinese website!