程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> C# MessageBox用法實例 (附效果圖)

C# MessageBox用法實例 (附效果圖)

編輯:關於C#
 

Displays a message box。Msdn MessageBox.show 方法

  1、  MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd

      當要顯示如圖3個按鈕時,並要獲得單擊不同按鈕的進行不同的相應時,可以在MessageBoxButtons後面添加一個。(應該英文的點,此處為了醒目,用中文代替)可以看到提示框下方需要幾個按鈕的不同選擇,如下圖:

MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd   if (MessageBox.Show("顯示提示信息", "標題", MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { //單擊是要進行的相應處理 }

 MessageBox.Show()的返回值是 yes 、no, ok還是cancel,那需要自己在show()方法中對它可以顯示的選擇按鈕進行設置。也就是說單擊不同的按鈕其返回值是不一樣的。

 

EG:

MessageBox()在C#中使用時,通常用MessageBox的show方法來實現對話框的彈出,命名空間System.Windows.Forms

應用實例:
      DialogResult r1 = MessageBox.Show("顯示提示信息", "標題", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (r1.ToString()=="Yes")

            { MessageBox.Show("Yes");  }

            if (r1.ToString().Equals("No"))

            { MessageBox.Show("No"); }

            if (r1.ToString().Equals("Cancel"))

            {  MessageBox.Show("Cancel");  }

顯示效果:C  MessageBox用法實例 (附效果圖) - Complaint Free Wolrd - Complaint Free Wolrd

單擊“是”,會彈出Yes;單擊“否”,會彈出No;單擊“取消”,會彈出Cancel。

 

MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd

2、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd

 MessageBox.Show("只顯示提示信息!");
  MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 3、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd
 MessageBox.Show("顯示提示信息!", "標題");
  MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 4、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd
 if (MessageBox.Show("顯示提示信息", "標題", MessageBoxButtons.OKCancel) == DialogResult.OK)  {}
MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 5、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd   if (MessageBox.Show("顯示提示信息", "標題", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) {} 小注:可以給MessageBox加上一個Icon,.net提供常見的幾種Icon選擇。 Icon選擇:MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd
MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 6、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd if (MessageBox.Show("顯示提示信息", "標題", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)   { } 小注:可以改變MessageBox的默認焦點
MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 7、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd  if (MessageBox.Show("顯示提示信息","標題", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading) == DialogResult.OK)  {} 小注:反向顯示
MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 8、MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd    if (MessageBox.Show("顯示提示信息","標題", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign, true) == DialogResult.OK)   {}
MessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free WolrdMessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd 9、C  MessageBox用法實例 (附效果圖) - Complaint Free Wolrd - Complaint Free Wolrd   MessageBox.Show(" 7 個參數+幫助菜單+可用",                                 "提示",                                 MessageBoxButtons.OKCancel,                                 MessageBoxIcon.Warning,                                 MessageBoxDefaultButton.Button2,                                  MessageBoxOptions.RightAlign,   // 標題向右對齊                                  @"d:\1.doc" //指定幫助文件的路徑,點擊即可打開該路徑下的幫助文件。                                 );
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved