Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net

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?

like image 464
jyoung Avatar asked Oct 23 '08 15:10

jyoung


People also ask

What is a dialog box in VB?

There are many built-in dialog boxes to be used in Windows forms for various tasks like opening and saving files, printing a page, providing choices for colors, fonts, page setup, etc., to the user of an application. These built-in dialog boxes reduce the developer's time and workload.

Which property of Openfiledialog is set to add extension to file names if the user doesn't supply any extensions?

Property Valuetrue if the dialog box adds an extension to a file name if the user omits the extension; otherwise, false . The default value is true .

Which function is used for opening the file dialog box?

The Open dialog box lets the user specify the drive, directory, and the name of a file or set of files to open. You create and display an Open dialog box by initializing an OPENFILENAME structure and passing the structure to the GetOpenFileName function.


3 Answers

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.

like image 131
Paige Watson Avatar answered Nov 25 '22 06:11

Paige Watson


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

like image 20
Nescio Avatar answered Nov 25 '22 06:11

Nescio


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

like image 28
jyoung Avatar answered Nov 25 '22 06:11

jyoung