Hi all,
Small problem: just want the messagebox to appear in the center of the winform that has control. Any suggestions?
Thanks much,
Hi all,
Small problem: just want the messagebox to appear in the center of the winform that has control. Any suggestions?
Thanks much,
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Feb 23, 2008, 2:27 PM
Bechir BejaouiPosted Feb 23, 2008, 8:35 AM
MessageBox.Show Method (IWin32Window, String, String, MessageBoxButtons) method and you difine the IWin32Window as "this" to refer the parent form
If you are not satisfied by this solution, you can define a customized form as a message displayer an then you can play with "location" property to localize it.
Or you can define you customized library control to do the job
AlanPosted Feb 23, 2008, 7:54 AM
There is no way to control the position of the standard Windows MessageBox, even at Win32 level, as it is controlled by the OS itself.
Possible workarounds include using one of the custom MessageBoxes available on sites such as Code Project, whose position can be controlled, or writing your own.
You can also center the form itself in the middle of the screen, so that the standard MessageBox will then appear in the middle of that, by setting the form's StartPosition property to FormStartPosition.CenterScreen.
Niradhip ChakrabortyPosted Feb 22, 2008, 4:11 PM
Hey by default messagebox will appear in the center of the form. I dont know where you are facing the problem exactly.
U can try the following code:
DialogResult temp = MessageBox.Show("Are you sure,do you want to Exit?","Exit", MessageBoxButtons.OKCancel);
if (temp == DialogResult.OK)
{
System.Windows.Forms.Application.Exit();
}