using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace CsvView.UI { public static class MessageBoxEx { private static IWin32Window _owner; public static DialogResult Show(string text) { Initialize(); return MessageBox.Show(text); } public static DialogResult Show(string text, string caption) { Initialize(); return MessageBox.Show(text, caption); } public static DialogResult Show(string text, string caption, MessageBoxButtons buttons) { Initialize(); return MessageBox.Show(text, caption, buttons); } public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) { Initialize(); return MessageBox.Show(text, caption, buttons, icon); } public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton) { Initialize(); return MessageBox.Show(text, caption, buttons, icon, defButton); } public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options) { Initialize(); return MessageBox.Show(text, caption, buttons, icon, defButton, options); } public static DialogResult Show(IWin32Window owner, string text) { _owner = owner; Initialize(); return MessageBox.Show(owner, text); } public static DialogResult Show(IWin32Window owner, string text, string caption) { _owner = owner; Initialize(); return MessageBox.Show(owner, text, caption); } public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons) { _owner = owner; Initialize(); return MessageBox.Show(owner, text, caption, buttons); } public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) { _owner = owner; Initialize(); return MessageBox.Show(owner, text, caption, buttons, icon); } public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton) { _owner = owner; Initialize(); return MessageBox.Show(owner, text, caption, buttons, icon, defButton); } public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defButton, MessageBoxOptions options) { _owner = owner; Initialize(); return MessageBox.Show(owner, text, caption, buttons, icon, defButton, options); } [DllImport("user32.dll")] private static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle lpRect); [DllImport("user32.dll")] private static extern int MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); private static void Initialize() { } private static void CenterWindow(IntPtr hChildWnd) { Rectangle recChild = new Rectangle(0, 0, 0, 0); GetWindowRect(hChildWnd, ref recChild); int width = recChild.Width - recChild.X; int height = recChild.Height - recChild.Y; Rectangle recParent = new Rectangle(0, 0, 0, 0); GetWindowRect(_owner.Handle, ref recParent); Point ptCenter = new Point(0, 0); ptCenter.X = recParent.X + ((recParent.Width - recParent.X) / 2); ptCenter.Y = recParent.Y + ((recParent.Height - recParent.Y) / 2); Point ptStart = new Point(0, 0); ptStart.X = (ptCenter.X - (width / 2)); ptStart.Y = (ptCenter.Y - (height / 2)); ptStart.X = (ptStart.X < 0) ? 0 : ptStart.X; ptStart.Y = (ptStart.Y < 0) ? 0 : ptStart.Y; MoveWindow(hChildWnd, ptStart.X, ptStart.Y, width, height, false); } } }