Click here to Skip to main content
15,877,103 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
am trying to view my windows forms in a maximized window but i want it to automatically do that the moment it loads not by clicking the maximizing button

What I have tried:

public partial class AdminPage : Form
    {
        public AdminPage()
        {
            InitializeComponent();                    
        }


        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;
            }
        }
C#

Posted
Updated 16-Jan-23 2:38am

1 solution

Just add the setting to the form constructor after the call to InitializeComponent:
C#
public AdminPage()
{
    InitializeComponent();
    this.WindowState = FormWindowState.Maximized;
}
 
Share this answer
 
Comments
CPallini 16-Jan-23 8:45am    
5.
Richard MacCutchan 16-Jan-23 8:49am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900