static public DialogResult Show(string message, string title,
MessageBoxButtons buttons)
{
// Create a host form that is a TopMost window which will be the
// parent of the MessageBox.
Form topmostForm = new Form();
// We do not want anyone to see this window so position it off the
// visible screen and make it as small as possible
topmostForm.Size = new System.Drawing.Size(1, 1);
topmostForm.StartPosition = FormStartPosition.Manual;
System.Drawing.Rectangle rect = SystemInformation.VirtualScreen;
topmostForm.Location = new System.Drawing.Point(rect.Bottom + 10,
rect.Right + 10);
topmostForm.Show();
// Make this form the active form and make it TopMost
topmostForm.Focus();
topmostForm.BringToFront();
topmostForm.TopMost = true;
// Finally show the MessageBox with the form just created as its owner
DialogResult result = MessageBox.Show(topmostForm, message, title,
buttons);
topmostForm.Dispose(); // clean it up all the way
return result;
}
本文介绍了一个自定义的MessageBox实现方法,通过创建一个置顶窗体作为消息框的父窗体,确保消息框总是位于最上层显示。这种方法适用于需要特别强调消息提示的应用场景。
4317

被折叠的 条评论
为什么被折叠?



