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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Feb 22, 2008, 11:11 AM EST
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();
}
AlanRank #669 · 3.6K reputationPosted Feb 23, 2008, 2:54 AM EST
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.
Bechir BejaouiRank #144 · 15.9K reputationPosted Feb 23, 2008, 3:35 AM EST
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
AlanRank #669 · 3.6K reputationPosted Feb 23, 2008, 9:27 AM EST