public static Internal.Windows.Constants.User32.MessageDialogStyles GetMessageDialogStyles(MessageDialog dialog) { Internal.Windows.Constants.User32.MessageDialogStyles styles = Internal.Windows.Constants.User32.MessageDialogStyles.OK; switch (dialog.Buttons) { case MessageDialogButtons.AbortRetryIgnore: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.AbortRetryIgnore; switch (dialog.DefaultButton) { case CommonDialogResult.Abort: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.Retry: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Ignore: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton4; break; } } break; } case MessageDialogButtons.CancelTryContinue: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.CancelTryContinue; switch (dialog.DefaultButton) { case CommonDialogResult.Cancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.TryAgain: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Continue: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton4; break; } } break; } case MessageDialogButtons.OK: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.OK; switch (dialog.DefaultButton) { case CommonDialogResult.OK: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } } break; } case MessageDialogButtons.OKCancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.OKCancel; switch (dialog.DefaultButton) { case CommonDialogResult.OK: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.Cancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } } break; } case MessageDialogButtons.RetryCancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.RetryCancel; switch (dialog.DefaultButton) { case CommonDialogResult.Retry: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.Cancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } } break; } case MessageDialogButtons.YesNo: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.YesNo; switch (dialog.DefaultButton) { case CommonDialogResult.Yes: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.No: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } } break; } case MessageDialogButtons.YesNoCancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.YesNoCancel; switch (dialog.DefaultButton) { case CommonDialogResult.Yes: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton1; break; } case CommonDialogResult.No: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton2; break; } case CommonDialogResult.Cancel: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton3; break; } case CommonDialogResult.Help: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultButton4; break; } } break; } } switch (dialog.Icon) { case MessageDialogIcon.Error: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.IconError; break; } case MessageDialogIcon.Information: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.IconInformation; break; } case MessageDialogIcon.Question: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.IconQuestion; break; } case MessageDialogIcon.Warning: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.IconWarning; break; } } switch (dialog.Modality) { case MessageDialogModality.ApplicationModal: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.ApplicationModal; break; } case MessageDialogModality.SystemModal: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.SystemModal; break; } case MessageDialogModality.TaskModal: { styles |= Internal.Windows.Constants.User32.MessageDialogStyles.TaskModal; break; } } if (dialog.ShowHelp) styles |= Internal.Windows.Constants.User32.MessageDialogStyles.Help; if (dialog.DefaultDesktopOnly) styles |= Internal.Windows.Constants.User32.MessageDialogStyles.DefaultDesktopOnly; if (dialog.ServiceNotification) styles |= Internal.Windows.Constants.User32.MessageDialogStyles.ServiceNotification; return styles; }
private CommonDialogResult ShowMessageDialogInternal(MessageDialog dialog) { Internal.Windows.Constants.User32.MessageDialogStyles styles = Win32MessageDialog.GetMessageDialogStyles(dialog); string title = dialog.Title; if (String.IsNullOrEmpty(dialog.Title)) title = " "; IntPtr hWnd = GetHandleByControl(dialog.Parent); Internal.Windows.Constants.User32.MessageDialogResponses retval = Internal.Windows.Methods.User32.MessageBox(hWnd, dialog.Content, title, styles); return CommonDialogResultFromWin32(retval); }
public static DialogResult ShowDialog(string prompt, string title = null, MessageDialogButtons buttons = MessageDialogButtons.OK, MessageDialogIcon icon = MessageDialogIcon.None, MessageDialogModality modality = MessageDialogModality.ApplicationModal, bool showHelp = false, Control parent = null) { MessageDialog dialog = new MessageDialog(); dialog.Buttons = buttons; dialog.Content = prompt; dialog.Modality = modality; dialog.Icon = icon; dialog.Title = title; dialog.ShowHelp = showHelp; dialog.Parent = parent; return dialog.ShowDialog(); }