MessageBox.Show使用

         if (MessageBox.Show("请确认退出?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes){Environment.Exit(0);}else{e.Cancel = true;}

MessageBox.Show有21种使用方法,其中
string text, 文本
string caption, 标题
System.Windows.Forms.MessageBoxButtons buttons, 指定在消息框中显示哪些按钮。
System.Windows.Forms.MessageBoxIcon icon 指定在消息框中显示哪个图标
这四个是最常使用的参数。
System.Windows.Forms.MessageBoxDefaultButton defaultButton 指定消息框中的默认按钮
System.Windows.Forms.MessageBoxOptions options 可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 0。
bool displayHelpButton 如果显示“帮助”按钮,则为 true;否则为 false。 默认值为 false。
string helpFilePath 用户单击“帮助”按钮时显示的“帮助”文件的路径和名称
这四个参数有时也会用到,其他的暂时没用到
返回值:DialogResult类型

在屏幕的最前面弹出消息框

MessageBox.Show("要弹的信息。", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

ServiceNotification 消息框显示在活动桌面上。
调用方是一种服务,用于将事件通知用户。即使没有用户登录到计算机,该功能也会在当前活动桌面上显示一个消息框。

DefaultDesktopOnly 消息框显示在活动桌面上。
此常数与 ServiceNotification 相同,只是系统仅在交互窗口站的默认桌面上显示消息框。
DefaultDesktopOnly 将使引发 MessageBox 的应用程序失去焦点。 显示的 MessageBox 将不使用视觉样式。

RightAlign 消息框文本右对齐。
RtlReading 指定消息框文本按从右到左的阅读顺序显示。

消息框淡出

似乎得使用窗体达到效果
窗体参考资料:几种窗口淡入淡出效果代码

自动关闭消息框

调用WinAPI

 public class MessageTip{[DllImport("user32.dll", SetLastError = true)]static extern IntPtr FindWindow(string lpClassName, string lpWindowName);public const int WM_CLOSE = 0x10;[DllImport("user32.dll", EntryPoint = "SendMessageA")]public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);public static bool HasMessageBox(string caption){IntPtr dlg = FindWindow(null, caption);if (dlg == IntPtr.Zero)return true;elsereturn false;}public void  ShowMessageBoxTimeout(string text, string caption, MessageBoxButtons buttons, int timeout){ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox), new CloseState(caption, timeout));MessageBox.Show(text, caption, buttons);}private void CloseMessageBox(object state){CloseState closeState = state as CloseState;Thread.Sleep(closeState.Timeout);IntPtr dlg = FindWindow(null, closeState.Caption);if (dlg != IntPtr.Zero){SendMessage(dlg, WM_CLOSE, 0, 0);}}private class CloseState{private int _Timeout;/// <summary>/// In millisecond/// </summary>public int Timeout{get{return _Timeout;}}private string _Caption;/// <summary>/// Caption of dialog/// </summary>public string Caption{get{return _Caption;}}public CloseState(string caption, int timeout){_Timeout = timeout;_Caption = caption;}}}

其他消息框

在 C# 中,可以使用 NotifyIcon 类来创建系统托盘图标,并通过弹出消息框来实现新消息提醒

private void Form1_Load(object sender, EventArgs e)
{   // 创建 NotifyIcon 对象 NotifyIcon notifyIcon = new NotifyIcon();   // 设置图标、文本和提示信息   notifyIcon.Icon = new Icon("icon.ico");   notifyIcon.Text = "My App";    notifyIcon.Visible = true;   notifyIcon.ShowBalloonTip(5000, "New Message", "You have a new message!", ToolTipIcon.Info);}

利用 C# 实现任务栏通知带皮肤窗口调用API
动画窗体通知消息
右下角自定义弹窗
自动关闭且倒计时

【c#基础-MessageBox】MessageBox的使用和消息框相关推荐

  1. Qt学习之路之QMessageBox消息框

    下面是 QMessageBox 的 实例: 开发环境: VS 2013, Qt版本: 5.4.0 下面附上代码: #include <QtWidgets/QApplication> #in ...

  2. 【转】WPF自定义控件与样式(13)-自定义窗体Window 自适应内容大小消息框MessageBox...

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: 自定义Window窗体样式: 基于自定义窗体实现自定义MessageB ...

  3. MessageBox消息框 1126

    MessageBox消息框 1126 使用方式 MessageBox.Show(提示内容)MessageBox.Show(提示内容,提示标题)MessageBox.Show(提示内容,提示标题,Mes ...

  4. C# 中的MessageBox 弹出提示框(消息框)的用法

    刚好用到MessageBox  ,所以就在网上查着学习了一下. MessageBox.Show(<字符串> Text, <字符串> Title, <整型> nTyp ...

  5. wpf MessageBox 消息框

    MessageBox 类 显示消息框. MessageBoxButton 枚举 指定在消息框显示的按钮. 作为MessageBox.Show 方法的参数 OK 该消息框显示 确定 按钮. OKCanc ...

  6. .NET MessageBox 网页弹出消息框

    方法一:     #region Alert 弹出消息框  /// <summary>        /// 弹出消息框        /// </summary>       ...

  7. 消息框messagebox的使用

    学习目标 功能用途 四种格式 方式二 第三种 方式四 消息框的返回值 例子 验证输入 合法性验证 演练 小结

  8. RabbitMQ-从基础到实战(3)— 消息的交换(上)

    转载请注明出处 0.目录 RabbitMQ-从基础到实战(1)- Hello RabbitMQ RabbitMQ-从基础到实战(2)- 防止消息丢失 RabbitMQ-从基础到实战(4)- 消息的交换 ...

  9. vba:消息框基础,msgbox

    常量 常量值 说明 vbOKOnly 0 只显示"确定"按钮(缺省值) VbOKCancel 1 显示"确定"和"取消"按钮 VbAbort ...

最新文章

  1. RX学习笔记:正则表达式
  2. 【AI初识境】被Hinton,DeepMind和斯坦福嫌弃的池化,到底是什么?
  3. 网络通信-1(InetAddress、UDP、TCP、DatagramPacket、DatagramSocket、UDP通信示例)
  4. (0.3)HarmonyOS鸿蒙开发工具DevEco Studio 模拟器使用
  5. MySQL中with rollup的用法
  6. dw选项卡怎么设置_EXCEL入门之设置
  7. 快速解决Git最常见问题
  8. Gradle插件开发- 无侵入的函数运行时间统计的实现
  9. Eagle 画板-拼板-输出Gerber到SeeedStudio打样过程笔记
  10. vscode快速下载方法
  11. UEFI安装win10+manjaro双系统
  12. HTML生成Word文档,可自定义Word文档页眉、页脚、分页。
  13. 微信公众号服务器需要备案,微擎不备案可以用吗?微信公众号开发域名一定要备案吗?...
  14. Alpha 完结撒花 —— 事后诸葛亮
  15. 【IC验证】Questasim使用指导
  16. 面试——HR问你的职业规划,应该怎样回答?
  17. 服务器dns劫持修复,电脑DNS被劫持怎么修复 电脑dns被劫持解决方法
  18. LNMP搭建HDwiki
  19. Luat 功能开发教程(十八) 阿里云
  20. 尚融宝——阿里云短信验证功能(sms)

热门文章

  1. Win7升为Win10以及win7系统的重装
  2. 视图、创建视图的语法、视图的作用
  3. 手机高速访问an web方法
  4. 【人工智能AI】禅与计算机程序设计艺术:文心一言 vs ChatGPT对比:文心一言当然不仅仅只是“问答对话”那么简单,背后是 “人工智能的全栈技术体系”!
  5. parameterType是必须写的吗?
  6. 数据库连接池,几种开源的数据库连接池
  7. dede 留言簿 多个
  8. 解决多线程安全问题的几种方式?
  9. 数据挖掘技术及其应用现状
  10. 旺店通·企业奇门与用友BIP旺店通销售出库单对接销售订单