运行时设置窗体最大化

  this.WindowState = FormWindowState.Maximized;  
 
public partial class MainForm : Form {     public MainForm()     {         InitializeComponent();         // this is the default         this.WindowState = FormWindowState.Normal;         this.StartPosition = FormStartPosition.WindowsDefaultBounds;         // check if the saved bounds are nonzero and visible on any screen         if (Settings.Default.WindowPosition != Rectangle.Empty &&             IsVisibleOnAnyScreen(Settings.Default.WindowPosition))         {             // first set the bounds             this.StartPosition = FormStartPosition.Manual;             this.DesktopBounds = Settings.Default.WindowPosition;             // afterwards set the window state to the saved value (which could be Maximized)             this.WindowState = Settings.Default.WindowState;         }         else         {             // this resets the upper left corner of the window to windows standards             this.StartPosition = FormStartPosition.WindowsDefaultLocation;             // we can still apply the saved size             this.Size = Settings.Default.WindowPosition.Size;         }     }     private bool IsVisibleOnAnyScreen(Rectangle rect)     {         foreach (Screen screen in Screen.AllScreens)         {             if (screen.WorkingArea.IntersectsWith(rect))             {                 return true;             }         }         return false;     }     protected override void OnClosed(EventArgs e)     {         base.OnClosed(e);         // only save the WindowState if Normal or Maximized         switch (this.WindowState)         {             case FormWindowState.Normal:             case FormWindowState.Maximized:                 Settings.Default.WindowState = this.WindowState;                 break;             default:                 Settings.Default.WindowState = FormWindowState.Normal;                 break;         }         // reset window state to normal to get the correct bounds         // also make the form invisible to prevent distracting the user         this.Visible = false;         this.WindowState = FormWindowState.Normal;         Settings.Default.WindowPosition = this.DesktopBounds;         Settings.Default.Save();     } }
<?xml version='1.0' encoding='utf-8'?> <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ScreenTest" GeneratedClassName="Settings">     <Profiles />     <Settings>         <Setting Name="WindowPosition" Type="System.Drawing.Rectangle" Scope="User">             <Value Profile="(Default)">0, 0, 0, 0</Value>         </Setting>         <Setting Name="WindowState" Type="System.Windows.Forms.FormWindowState" Scope="User">             <Value Profile="(Default)">Normal</Value>         </Setting>     </Settings> </SettingsFile>

你可能感兴趣的:(windows,user,Class,encoding,Standards)