網站首頁 編程語言 正文
前言
我們在學習Windows應用程序開發中,經常會用到消息對話框給用戶或者管理員一些的消息提示,它們都是基于對MessageBox類的消息對話框的一種應用,在C#中,MessageBox消息對話框位于System.Windows.Forms命名空間中。一般情況下,一個消息對話框包含信息提示文字內容,消息對話框標題文字,用戶響應按鈕及信息圖標的內容,我們可以根據自己的需求設置消息對話框。好了我們開始學習吧!!!!
1.創建窗體文件
注:在取文件名或者項目名盡量別和系統的變量名沖突,就是別取一樣的比如博主文件名取的MessageBox到后面又要改
1.1 設計界面
2.認識消息對話框的屬性和圖標
AbortRetryIgnore 在消息框對話框中提供“中止”、“重試”和“忽略”三個按鈕
OK 在消息框對話框中提供“確定”按鈕
OKCancel 在消息框對話框中提供“確定”和“取消”兩個按鈕
RetryCancel 在消息框對話框中提供“重試”和“取消”兩個按鈕
YesNo 在消息框對話框中提供“是”和“否”兩個按鈕
YesNoCancel 在消息框對話框中提供“是”、“否”和“取消”三個按鈕
3.MessageBox消息對話框實現效果
3.1 AbortRetryIgnore效果展示
消息提示框類型使用 AbortRetryIgnore在消息框對話框中提供“中止”、“重試”和“忽略”三個按鈕,圖標設置為Warning,警告圖標
3.2 OK效果展示
消息提示框類型使用OK在消息框對話框中提供“確定”按鈕,圖標設置為Asterisk,消息圖標
3.3 OKCancel效果展示
消息提示框類型使用OKCancel在消息框對話框中提供“確定”和“取消”兩個按鈕,圖標設置為Error,錯誤警告圖標
3.4 RetryCancel效果展示
消息提示框類型使用RetryCancel在消息框對話框中提供“重試”和“取消”兩個按鈕,圖標設置為Question,問號系統圖標
3.5 YesNo效果展示
消息提示框類型使用 YesNo在消息框對話框中提供“是”和“否”兩個按鈕,圖標設置為Question,問號系統圖標
3.6 YesNoCancel效果展示
消息提示框類型使用YesNoCancel在消息框對話框中提供“是”、“否”和“取消”三個按鈕,圖標為None空白圖標
4.代碼展示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestMessageBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“中止”、“重試”和“忽略”三個按鈕!", "測試測試", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);//第一個參數文本表示提示內容,第二個參數文本表示消息框標題,第三個參數MessageBoxButtons消息框的按鈕樣式,第四個參數MessageBoxIcon表示系統圖標,第五個參數MessageBoxDefaultButton表示提示框默認選擇的按鈕
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“確定”按鈕!", "測試測試", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“確定”和“取消”兩個按鈕!", "測試測試", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“重試”和“取消”兩個按鈕!", "測試測試", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
}
private void button5_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“是”和“否”兩個按鈕!", "測試測試", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
}
private void button6_Click(object sender, EventArgs e)
{
MessageBox.Show("測試一下消息對話框在消息框對話框中提供“是”、“否”和“取消”三個按鈕!", "測試測試", MessageBoxButtons.YesNoCancel, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}
}
}
總結
文章介紹了MessageBox.show的消息框的使用,它6個消息提示框按鈕展示樣式效果和它的屬性名還是很容易理解 的比如OK就是一個確定按鈕,消息提示框在C#窗體應用編程中使用頻率特別高,有時候就經常把這個消息提示框用來起到斷點的作用,博主雖然知道vs2019怎么用斷點,但是還是喜歡用這個MessageBox.show來輸出我需要的值,哈哈哈,MessageBox.show的輸出類型是String類型,如果你把整形輸出就要用Convert.ToString()轉一下。
原文鏈接:https://juejin.cn/post/7130242838310158344
相關推薦
- 2022-03-14 跨域問題Response to preflight request doesn't pass acc
- 2022-09-14 Python?boxplot?用法詳解_python
- 2022-11-07 C語言字符串函數模擬實現流程介紹_C 語言
- 2022-07-12 Python根據交集、并集對比兩個文件
- 2022-04-16 pycharm如何設置自動生成作者信息_python
- 2022-05-09 Python數據結構與算法中的棧詳解(1)_python
- 2022-11-17 使用Python中Tkinter模塊的Treeview?組件顯示ini文件操作_python
- 2022-03-04 element-ui 固定彈窗底部的按鈕
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支