BaseForm.ShowMessage メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したテキストを使用するメッセージ ボックスを表示します。
オーバーロード
ShowMessage(String) |
指定したテキストを使用するメッセージ ボックスを表示します。 |
ShowMessage(String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) |
指定したテキスト、ボタン セット、シンボル、および既定のボタンを使用するメッセージ ボックスを表示します。 |
ShowMessage(String)
指定したテキストを使用するメッセージ ボックスを表示します。
protected public:
void ShowMessage(System::String ^ message);
protected internal void ShowMessage (string message);
member this.ShowMessage : string -> unit
Protected Friend Sub ShowMessage (message As String)
パラメーター
- message
- String
表示するメッセージ。
例
次の例では、ウィンドウ ジオメトリを基本設定ストアに保存します。 基本設定サービスが の場合は null
、メッセージが表示されます。
void persistWindowVals() {
IPreferencesService prefService = (IPreferencesService)
GetService(typeof(IPreferencesService));
if (prefService == null) {
ShowMessage("Null PreferencesService");
return;
}
if (prefService != null) {
PreferencesStore prefStore = prefService.GetPreferencesStore(
new Guid(PreferenceKey));
if (WindowState == FormWindowState.Maximized) {
prefStore.SetValue(MaximizedPreferenceKey, true, false);
} else if (WindowState != FormWindowState.Minimized) {
prefStore.SetValue(WidthPreferenceKey, Size.Width, -1);
prefStore.SetValue(HeightPreferenceKey, Size.Height, -1);
prefStore.SetValue(YPosPreferenceKey, Location.Y, -1);
prefStore.SetValue(XPosPreferenceKey, Location.X, -1);
prefStore.SetValue(MaximizedPreferenceKey, false, false);
}
}
}
適用対象
ShowMessage(String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)
指定したテキスト、ボタン セット、シンボル、および既定のボタンを使用するメッセージ ボックスを表示します。
protected public:
System::Windows::Forms::DialogResult ShowMessage(System::String ^ message, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
protected internal System.Windows.Forms.DialogResult ShowMessage (string message, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
member this.ShowMessage : string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Protected Friend Function ShowMessage (message As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult
パラメーター
- message
- String
表示するメッセージ。
- buttons
- MessageBoxButtons
MessageBoxButtons 値のいずれか 1 つ。
- icon
- MessageBoxIcon
MessageBoxIcon 値のいずれか 1 つ。
- defaultButton
- MessageBoxDefaultButton
MessageBoxDefaultButton 値のいずれか 1 つ。
戻り値
DialogResult 値のいずれか 1 つ。
例
次の例では、変更を保存するようにユーザーに求めます。
protected override void OnFormClosing(FormClosingEventArgs e) {
base.OnFormClosing(e);
CloseReason reason = e.CloseReason;
if (reason != CloseReason.UserClosing &&
reason != CloseReason.ApplicationExitCall)
return;
IServiceProvider serviceProvider = this.ServiceProvider;
if (serviceProvider == null)
return;
IConnectionManager connectionManager = (IConnectionManager)
GetService(typeof(IConnectionManager));
if ((connectionManager == null) ||
(!connectionManager.IsDirty)) // nothing to save
return;
DialogResult result = ShowMessage(
"The connection list has changed. Save changes?",
MessageBoxButtons.YesNoCancel, // button set
MessageBoxIcon.Question, // Icon
MessageBoxDefaultButton.Button1); // Default btn
if (result == DialogResult.Yes) {
connectionManager.Save();
} else if (result == DialogResult.Cancel) {
e.Cancel = true;
}
}