好头痛, user 不会操作程式导致问题连连,灾情严重.
老板大大, 希望程式能跳出MessageBox对话盒并连接说明档( help.htm).
开始研究MessageBox.Show语法…….
首先透过伟大google大神找到
MessageBox . Show方法(String, String, MessageBoxButtons)
开始研究一下…….
正常版显示没有回传值程式码 :
语法说明如下:
public static DialogResult Show(string text, string caption);
// 摘要:
// 顯示含有指定文字和標題的訊息方塊。
//
// 參數:
// text:
// 要顯示在訊息方塊中的文字。
//
// caption:
// 要顯示在訊息方塊標題列中的文字。
实际coding…..
essageBox.Show("歡迎來到C#世界........", "你好 老套但是不會膩顯示
执行结果如下:
有回传值…. 语法。
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons);
// 摘要:
// 顯示含有指定文字、標題和按鈕的訊息方塊。
//
// 參數:
// text:
// 要顯示在訊息方塊中的文字。
//
// caption:
// 要顯示在訊息方塊標題列中的文字。
//
// buttons:
// 其中一個 System.Windows.Forms.MessageBoxButtons 值,指定要在訊息方塊中顯示哪些按鈕。
//
// 傳回:
// 其中一個 System.Windows.Forms.DialogResult 值。
//
// 例外狀況:
// T:System.ComponentModel.InvalidEnumArgumentException:
// 指定的 buttons 參數不是 System.Windows.Forms.MessageBoxButtons 的成員。
//
// T:System.InvalidOperationException:
// 嘗試在不執行使用者互動模式的處理序中顯示 System.Windows.Forms.MessageBox。這個由 System.Windows.Forms.SystemInformation.UserInteractive
// 屬性所指定。
实际coding….
//寫法一
//DialogResult Result;
//Result = MessageBox.Show("歡迎來到C#世界........", "你好 老套但是不會膩顯示", MessageBoxButtons.OKCancel);
//寫法二
DialogResult Result = MessageBox.Show("歡迎來到C#世界........", "你好 老套但是不會膩顯示", MessageBoxButtons.OKCancel);
if (Result == DialogResult.OK)
{
MessageBox.Show("按下OK", "有回傳值顯示");
}
else if (Result == DialogResult.Cancel)
{
MessageBox.Show("按下Cancel", "有回傳值顯示");
}
执行结果如下
if (Result == DialogResult.OK)
{
MessageBox.Show("按下OK", "有回傳值顯示");
}
else if (Result == DialogResult.Cancel)
{
MessageBox.Show("按下Cancel", "有回傳值顯示");
}
有help档语法说明
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath);
// 摘要:
// 使用指定的說明檔,顯示含有指定文字、標題、按鈕、圖示、預設按鈕、選項和 [說明] 按鈕的訊息方塊。
//
// 參數:
// text:
// 要顯示在訊息方塊中的文字。
//
// caption:
// 要顯示在訊息方塊標題列中的文字。
//
// buttons:
// 其中一個 System.Windows.Forms.MessageBoxButtons 值,指定要在訊息方塊中顯示哪些按鈕。
//
// icon:
// 其中一個 System.Windows.Forms.MessageBoxIcon 值,指定那個圖示要顯示在訊息方塊中。
//
// defaultButton:
// 其中一個 System.Windows.Forms.MessageBoxDefaultButton 值,指定訊息方塊的預設按鈕。
//
// options:
// 其中一個 System.Windows.Forms.MessageBoxOptions 值,指定訊息方塊使用的顯示及關聯的選項。如果要使用預設值,可以傳遞
// 0。
//
// helpFilePath:
// 使用者按一下 [說明] 按鈕時所顯示說明檔的路徑和名稱。
//
// 傳回:
// 其中一個 System.Windows.Forms.DialogResult 值。
//
// 例外狀況:
// T:System.ComponentModel.InvalidEnumArgumentException:
// buttons 不是 System.Windows.Forms.MessageBoxButtons 的成員。-或-icon 不是 System.Windows.Forms.MessageBoxIcon
// 的成員。-或-指定的 defaultButton 參數不是 System.Windows.Forms.MessageBoxDefaultButton 的成員。
//
// T:System.InvalidOperationException:
// 嘗試在不執行使用者互動模式的處理序中顯示 System.Windows.Forms.MessageBox。這個由 System.Windows.Forms.SystemInformation.UserInteractive
// 屬性所指定。
//
// T:System.ArgumentException:
// options 指定 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 System.Windows.Forms.MessageBoxOptions.ServiceNotification。-或-buttons
// 指定了無效的 System.Windows.Forms.MessageBoxButtons 組合。
helpFilePath:
//使用者按一下[说明]按钮时所显示说明档的路径和名称。
1. 准备要说明档: help.htm 或help.chm
2.指定路径@"C:/folder/help.htm");
3.指定路径@"C:/folder/help.chm");
coding…
DialogResult Result = MessageBox.Show("Delete this user ?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, @"C:/folder/help.htm");
if (Result == DialogResult.OK)
{
MessageBox.Show("按下OK", "有回傳值顯示");
}
else if (Result == DialogResult.Cancel)
{
MessageBox.Show("按下Cancel", "有回傳值顯示");
}
执行结果如下: