📄 messagebox.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Aspnet.Snapin;
//该源码下载自www.51aspx.com(51aspx.com)
namespace SkyiSite.Tooltip
{
/// <summary>
///MessageBox 的摘要说明
/// </summary>
public class MessageBox
{
/// <summary>
/// 显示消息框,换行\n
/// 0,确认 1,确认或取消 2,终止,重试,忽略 3,是,否,取消 4,是,否 5,重试,取消 6,取消,重试(DialogResult.TryAgain),继续
/// </summary>
/// <param name="intPtr"></param>
/// <param name="Text">要显示的消息内容</param>
/// <param name="Caption">消息标题</param>
/// <param name="MsgType">0,确认 1,确认或取消 2,终止,重试,忽略 3,是,否,取消 4,是,否 5,重试,取消 6,取消,重试(DialogResult.TryAgain),继续</param>
/// <returns></returns>
public static DialogResult Show(IntPtr intPtr, string Text, string Caption, int MsgType)
{
DialogResult dialogResult = DialogResult.Error;
int resultType = 0;
switch (MsgType)
{
case 0://确认
AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 0);
dialogResult = DialogResult.Enter;
break;
case 1://确认或取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 1);
if (resultType == 1)
dialogResult = DialogResult.Enter;
else if (resultType == 2)
dialogResult = DialogResult.Cancel;
break;
case 2://终止,重试,忽略
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 2);
if (resultType == 3)
{
dialogResult = DialogResult.Stop;
}
else if (resultType == 4)
{
dialogResult = DialogResult.Try;
}
else if (resultType == 5)
{
dialogResult = DialogResult.Ignore;
}
break;
case 3://是,否,取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 3);
if (resultType == 6)
{
dialogResult = DialogResult.Yes;
}
else if (resultType == 7)
{
dialogResult = DialogResult.No;
}
else if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
break;
case 4: //是,否
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 4);
if (resultType == 6)
{
dialogResult = DialogResult.Yes;
}
else if (resultType == 7)
{
dialogResult = DialogResult.No;
}
break;
case 5://重试,取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 5);
if (resultType == 4)
{
dialogResult = DialogResult.Try;
}
else if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
break;
case 6://取消,重试,继续
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 6);
if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
else if (resultType == 10)
{
dialogResult = DialogResult.TryAgain;
}
else if (resultType == 11)
{
dialogResult = DialogResult.Continue;
}
break;
}
return dialogResult;
}
public static DialogResult Show(string Text)
{
return Show(Text, "", 0);
}
/// <summary>
/// 显示消息框,换行\n
/// 0,确认 1,确认或取消 2,终止,重试,忽略 3,是,否,取消 4,是,否 5,重试,取消 6,取消,重试(DialogResult.TryAgain),继续
/// </summary>
/// <param name="Text">要显示的消息内容</param>
/// <param name="Caption">消息标题</param>
/// <param name="MsgType">0,确认 1,确认或取消 2,终止,重试,忽略 3,是,否,取消 4,是,否 5,重试,取消 6,取消,重试(DialogResult.TryAgain),继续</param>
/// <returns></returns>
public static DialogResult Show(string Text, string Caption, int MsgType)
{
DialogResult dialogResult = DialogResult.Error;
IntPtr intPtr = AspNetManagementUtility.GetActiveWindow();
int resultType = 0;
switch (MsgType)
{
case 0://确认
AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 0);
dialogResult = DialogResult.Enter;
break;
case 1://确认或取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 1);
if (resultType == 1)
dialogResult = DialogResult.Enter;
else if (resultType == 2)
dialogResult = DialogResult.Cancel;
break;
case 2://终止,重试,忽略
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 2);
if (resultType == 3)
{
dialogResult = DialogResult.Stop;
}
else if (resultType == 4)
{
dialogResult = DialogResult.Try;
}
else if (resultType == 5)
{
dialogResult = DialogResult.Ignore;
}
break;
case 3://是,否,取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 3);
if (resultType == 6)
{
dialogResult = DialogResult.Yes;
}
else if (resultType == 7)
{
dialogResult = DialogResult.No;
}
else if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
break;
case 4: //是,否
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 4);
if (resultType == 6)
{
dialogResult = DialogResult.Yes;
}
else if (resultType == 7)
{
dialogResult = DialogResult.No;
}
break;
case 5://重试,取消
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 5);
if (resultType == 4)
{
dialogResult = DialogResult.Try;
}
else if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
break;
case 6://取消,重试,继续
resultType = AspNetManagementUtility.MessageBox(intPtr, Text, Caption, 6);
if (resultType == 2)
{
dialogResult = DialogResult.Cancel;
}
else if (resultType == 10)
{
dialogResult = DialogResult.TryAgain;
}
else if (resultType == 11)
{
dialogResult = DialogResult.Continue;
}
break;
}
return dialogResult;
}
}
public enum DialogResult
{
/// <summary>
/// 如果函数失败,则为 0
/// </summary>
Error = 0,
/// <summary>
/// 确认 1
/// </summary>
Enter,
/// <summary>
/// 取消 2
/// </summary>
Cancel,
/// <summary>
/// 终止 3
/// </summary>
Stop,
/// <summary>
/// 重试 4
/// </summary>
Try,
/// <summary>
/// 忽略 5
/// </summary>
Ignore,
/// <summary>
/// 是 6
/// </summary>
Yes,
/// <summary>
/// 否 7
/// </summary>
No,
/// <summary>
/// 重试 10
/// </summary>
TryAgain = 10,
/// <summary>
/// 继续 11
/// </summary>
Continue
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -