MessageBoxButtons 列舉
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定定義那個按鈕要顯示在 MessageBox 上的常數。
public enum class MessageBoxButtons
C#
public enum MessageBoxButtons
type MessageBoxButtons =
Public Enum MessageBoxButtons
- 繼承
名稱 | 值 | Description |
---|---|---|
AbortRetryIgnore | 2 | 訊息方塊包含 [中止]、[重試] 和 [忽略] 按鈕。 |
CancelTryContinue | 6 | 指定訊息方塊包含 [取消]、[重試] 和 [繼續] 按鈕。 |
OK | 0 | 訊息方塊包含 [確定] 按鈕。 |
OKCancel | 1 | 訊息方塊包含 [確定] 和 [取消] 按鈕。 |
RetryCancel | 5 | 訊息方塊包含 [重試] 和 [取消] 按鈕。 |
YesNo | 4 | 訊息方塊包含 [是] 和 [否] 按鈕。 |
YesNoCancel | 3 | 訊息方塊包含 [是]、[否] 和 [取消] 按鈕。 |
下列程式碼範例示範如何使用 MessageBox ,讓使用者有機會防止表單關閉。 此範例需要從 FormClosing 表單的 事件呼叫 方法。
private:
void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e)
{
// If the no button was pressed ...
if ((MessageBox::Show(
"Are you sure that you would like to close the form?",
"Form Closing", MessageBoxButtons::YesNo,
MessageBoxIcon::Question) == DialogResult::No))
{
// cancel the closure of the form.
e->Cancel = true;
}
}
C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
const string message =
"Are you sure that you would like to close the form?";
const string caption = "Form Closing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// If the no button was pressed ...
if (result == DialogResult.No)
{
// cancel the closure of the form.
e.Cancel = true;
}
}
Private Sub Form1_FormClosing( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing
Dim message As String = _
"Are you sure that you would like to close the form?"
Dim caption As String = "Form Closing"
Dim result = MessageBox.Show(message, caption, _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question)
' If the no button was pressed ...
If (result = DialogResult.No) Then
' cancel the closure of the form.
e.Cancel = True
End If
End Sub
這項列舉供 MessageBox 類別使用。
產品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |