How to center a form using showdialog (.NET Compact Framework)?

You can make an extension method that does the work for you.

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().

This is not working! I still see the form being randomly placed on the screen. – Gopinath Jan 16 '10 at 10:12 @Gopinath: that's odd; I tried out the code before posting it.Is there any other code setting the Location or Bounds property of the form?

– Fredrik Mörk Jan 16 '10 at 10:29 thanks fredrik. When tested on the device, the popup centered as expected. But when the application was ran on a PC, it did not center properly.

Many thanks for your help. – Gopinath Jan 19 '10 at 15:08.

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.

As noted in the question, the StartPosition property is not available in the . NET Compact Framework. – Fredrik Mörk Jan 19 '10 at 15:24 damn me!

I won't answer on stuff which I used that long ago.. really :) – hoodoos Jan 19 '10 at 20:59.

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.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions