Sunday, January 25, 2009

Starting the Dynamics GP AddIn form centered in the screen

While working on VSToolkit and VSMenus, I had a problem in starting the AddIn form centered in the screen; I tried to change “StartPosition” to Center Screen and Center Parent with no success, the form keep opening in the left top corner of the screen which is very annoying to the end users.

I found that the tool is ignoring the “StartPosition” property and is using the “Location” property instead, but the location cannot be fixed since the screen resolution is changeable.

To workaround this issue I have created the following code segment that gets the screen resolution and set the form boundaries to the screen center

Just add the following code segment to your form load:

Me.SetBounds(Math.Round((Screen.PrimaryScreen.Bounds.Width / 2) - (Me.Width / 2), 0), Math.Round((Screen.PrimaryScreen.Bounds.Height / 2) - (Me.Height / 2), 0), Me.Width, Me.Height)

Hope this helps!

Mohammad R. Daoud
Software Development Manager
+962 - 79 - 999 65 85
Dynamics Innovations


Steve Endow said...

Thanks for the post--I came to the same conclusion a while ago and ended up writing the same code to just center the window.

An interesting variant of this is to be able to center the AddIn window relative to its GP "parent" window:

I haven't found a solution to that one yet, but it would be nice!

1antares1 said...

Gracias. Me ha funcionado.

Un abrazo.

Related Posts:

Related Posts with Thumbnails