I want to centre a popup form launched using Form.ShowDialog() in .NET Compact Framework. I dont see any property like StartPosition in .NET CF Form object.
Can someone please suggest me how to centre popups in .NET CF 3.5?
At its most basic level it keeps the process alive until the last form is closed. Show() method shows a windows form in a non-modal state. ShowDialog() method shows a window in a modal state and stops execution of the calling context until a result is returned from the windows form open by the method.
ShowDialog() Shows the form as a modal dialog box. ShowDialog(IWin32Window) Shows the form as a modal dialog box with the specified owner.
You can make an extension method that does the work for you:
public static class FormExtensions
{
public static void CenterForm(this Form theForm)
{
theForm.Location = new Point(
Screen.PrimaryScreen.WorkingArea.Width / 2 - theForm.Width / 2,
Screen.PrimaryScreen.WorkingArea.Height / 2 - theForm.Height / 2);
}
}
You call it like this:
TheDialogForm f = new TheDialogForm();
f.CenterForm();
f.ShowDialog();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With