How do we make forms size, location and fit into main form
at the fixed position?
1
Expert's answer
2012-03-20T11:28:00-0400
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; } }
Comments
Leave a comment