Answer to Question #3688 in C# for yashveer singh

Question #3688
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;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS