MessageBoxButtons Enum
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger konstanter som definierar vilka knappar som ska visas på en MessageBox.
public enum class MessageBoxButtons
public enum MessageBoxButtons
type MessageBoxButtons =
Public Enum MessageBoxButtons
- Arv
Fält
| Name | Värde | Description |
|---|---|---|
| OK | 0 | Meddelanderutan innehåller en OK-knapp. |
| OKCancel | 1 | Meddelanderutan innehåller knapparna OK och Avbryt. |
| AbortRetryIgnore | 2 | Meddelanderutan innehåller knapparna Avbryt, Försök igen och Ignorera. |
| YesNoCancel | 3 | Meddelanderutan innehåller knapparna Ja, Nej och Avbryt. |
| YesNo | 4 | Meddelanderutan innehåller knapparna Ja och Nej. |
| RetryCancel | 5 | Meddelanderutan innehåller knapparna Försök igen och Avbryt. |
| CancelTryContinue | 6 | Anger att meddelanderutan innehåller knapparna Avbryt, Försök igen och Fortsätt. |
Exempel
I följande kodexempel visas hur du använder en MessageBox för att ge användaren en möjlighet att förhindra att ett formulär stängs. Det här exemplet kräver att metoden anropas från FormClosing händelsen i formuläret.
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;
}
}
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
Kommentarer
Den här uppräkningen används av MessageBox klassen.