#region Apache License 2.0
/*
Nuclex .NET Framework
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion // Apache License 2.0
using System;
using System.Windows.Forms;
namespace Nuclex.Windows.Forms.Messages {
/// Contains helper methods for the message service
public static class MessageServiceHelper {
/// Asks the user a question that can be answered with yes or no
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static DialogResult AskYesNo(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestion(
MessageBoxIcon.Question, text, MessageBoxButtons.YesNo
);
}
/// Asks the user a question that can be answered with ok or cancel
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static DialogResult AskOkCancel(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestion(
MessageBoxIcon.Question, text, MessageBoxButtons.OKCancel
);
}
///
/// Asks the user a question that can be answered with yes, no or cancel
///
///
/// Message service that will be used to display the question
///
/// Text that will be shown on the message box
/// The button the user has clicked on
public static DialogResult AskYesNoCancel(
this IMessageService messageService, MessageText text
) {
return messageService.ShowQuestion(
MessageBoxIcon.Question, text, MessageBoxButtons.YesNoCancel
);
}
/// Displays an informative message
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static void Inform(
this IMessageService messageService, MessageText text
) {
messageService.ShowNotification(MessageBoxIcon.Information, text);
}
/// Displays a warning
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static void Warn(
this IMessageService messageService, MessageText text
) {
messageService.ShowNotification(MessageBoxIcon.Warning, text);
}
/// Reports an error
///
/// Message service that will be used to display the warning
///
/// Text to be displayed on the warning message
public static void ReportError(
this IMessageService messageService, MessageText text
) {
messageService.ShowNotification(MessageBoxIcon.Error, text);
}
}
} // namespace Nuclex.Windows.Forms.Messages