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?
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?
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();
Set the left and Top properties on the of the form in 'frmDialog_Activated event
Private Sub frmDialog_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Me.Left = (frmMain.Width - Me.Width) / 2 ' AS Your Wish
Me.Top = (frmMain.Height - Me.Height) / 2 + 165 '' AS Your Wish
End Sub
If you want your popup form appear in center of screen by default you can just set a starting position for it in form properties, it should sound like 'Center parent'.
Something like that: form1.StartPosition = FormStartPosition.CenterScreen;