Files
netch/Netch/Utils/MessageBoxX.cs
ChsBuffer c9396bd6b2 捕捉到未处理错误打开日志
减少TUN/TAP设置路由表代码
日志细节优化
2020-07-28 16:10:26 +08:00

44 lines
1.6 KiB
C#

using System;
using System.Windows.Forms;
using Netch.Models;
namespace Netch.Utils
{
class MessageBoxX
{
/// <summary>
/// </summary>
/// <param name="text">内容</param>
/// <param name="title">自定义标题</param>
/// <param name="level">弹窗等级 (标题, 图标)</param>
/// <param name="confirm">需要确认</param>
/// <param name="owner">阻止 owner Focus() 直到 Messageox 被关闭</param>
public static DialogResult Show(string text, LogLevel level = LogLevel.INFO, string title = "", bool confirm = false, IWin32Window owner = null)
{
MessageBoxIcon msgIcon;
if (string.IsNullOrWhiteSpace(title))
title = level switch
{
LogLevel.INFO => "Information",
LogLevel.WARNING => "Warning",
LogLevel.ERROR => "Error",
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
};
msgIcon = level switch
{
LogLevel.INFO => MessageBoxIcon.Information,
LogLevel.WARNING => MessageBoxIcon.Warning,
LogLevel.ERROR => MessageBoxIcon.Exclamation,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
};
return MessageBox.Show(
owner: owner,
text: text,
caption: i18N.Translate(title),
buttons: confirm ? MessageBoxButtons.OKCancel : MessageBoxButtons.OK,
icon: msgIcon);
}
}
}