Question Centering Dialogs?

Swoop

Member
Joined
Dec 7, 2011
Messages
14
Programming Experience
Beginner
I hope this is the correct forum for questions like this so mods, please feel free to move it if not :)

Gents, I've been hunting for a way to center the vb.net MessageBox (and the rest of the Windows dialogs) but information on doing it appears to be somewhat scarce. I found some C# code at the CodeProject but was wondering if there is a pure vb.net/api solution for it.

I mean since dotnet has been around for awhile, you would think that it would have resolved a hundred times over by now. Please advise and thanks!

Mark
 
Last edited:
With a form shown as a dialog (ShowDialog) you have the StartPosition property that can be set, for example to CenterParent.
For built in dialogs such as the MessageBox that is not possible since the form object is not available, they center in screen by default.
Apart from that, did you search "messagebox center" ? I'm sure locating and placing any window is possible using native Windows functions.
 
Yeah, I've looked around and the vast majority of code is written for VB6. There are of course a few samples in C# with one even providing a .DLL that you can distribute with your app. What amazes me is that I can't seem to find a pure vb.net solution to centering the windows dialogs.

I'm not sure how to go about it in vb.net yet as I'm just starting to mess around with it. What would be nice is to have had someone already do the work so not only I can use the code, I can learn from it as well. Code like that then becomes very useful as it can lead to finding out how to call api .DLLs from the dotnet environment rather then guess.

Remember, there are varying degrees of class abstractions, many of which are unnecessary. So it's hard to tell at this stage what will be useful and what isn't. A working vb.net class that uses both a timer proc and a message hook would be cool (if you know where to find one)


Mark
 
Last edited:
I've posted a solution to the CodeProject and it should be available in the next couple of days.

Mark
 
Last edited:
Back
Top