Can I position .net's (Forms) Message box or Common dialogs?

12,446

Solution 1

As HTH explained above, there are ugly ways to do it. Here is a simple class that will wrap the dialog box and center it in the parent application/Form.

It takes the ugly ways and wraps them to something slightly more simple.

While I haven't implemented this or really delved into the source, it's a good place to start. CodeProject CenterDialog

Hope this helps.

Solution 2

Without digging into some ugly P/invoke code to find and move the window after it is displayed, this simply impossible. If you pursue this, the message box will "jump" to the new position, which is generally worse than not having it centered. If the position is truly that important, you are much better off creating your own message box, or adopting one from CodeProject.

HTH

Solution 3

After some digging I found http://support.microsoft.com/kb/180936. This works.

Share:
12,446
jyoung
Author by

jyoung

Updated on June 16, 2022

Comments

  • jyoung
    jyoung almost 2 years

    I am trying to get center of parent form, not center of screen behavior. Passing in the parent form seems to only control the ownership of the window. These classes are sealed, so I do not see how I can do any WinProc tricks. Rewriting the classes is not an appealing option. Any other ideas?