MessageBoxOptions 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 alternativ för en MessageBox.
Den här uppräkningen stöder en bitvis kombination av dess medlemsvärden.
public enum class MessageBoxOptions
[System.Flags]
public enum MessageBoxOptions
[<System.Flags>]
type MessageBoxOptions =
Public Enum MessageBoxOptions
- Arv
- Attribut
Fält
| Name | Värde | Description |
|---|---|---|
| DefaultDesktopOnly | 131072 | Meddelanderutan visas på det aktiva skrivbordet. Den här konstanten liknar |
| RightAlign | 524288 | Texten i meddelanderutan är högerjusterad. |
| RtlReading | 1048576 | Anger att meddelanderutans text visas med läsordning från höger till vänster. |
| ServiceNotification | 2097152 | Meddelanderutan visas på det aktiva skrivbordet. Anroparen är en tjänst som meddelar användaren om en händelse. Show visar en meddelanderuta på det aktuella aktiva skrivbordet, även om ingen användare är inloggad på datorn. |
Exempel
I följande exempel visas hur du visar en MessageBox med de alternativ som stöds av överlagringarna av MessageBox.Show en options parameter. När du har kontrollerat att en strängvariabel, ServerName, är tom, visar exemplet en MessageBox med en frågeruteikon, vilket ger användaren möjlighet att avbryta åtgärden. I exemplet används MessageBoxOptions.RightAlign uppräkningsmedlemmen för att justera texten till höger i dialogrutan.
Show Om metodens returvärde utvärderas till DialogResult.Yesstängs formuläret som visade MessageBox metoden.
private:
void validateUserEntry2()
{
// Checks the value of the text.
if ( serverName->Text->Length == 0 )
{
// Initializes the variables to pass to the MessageBox::Show method.
String^ message = "You did not enter a server name. Cancel this operation?";
String^ caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons::YesNo;
System::Windows::Forms::DialogResult result;
// Displays the MessageBox.
result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
if ( result == ::DialogResult::Yes )
{
// Closes the parent form.
this->Close();
}
}
}
private void validateUserEntry2()
{
// Checks the value of the text.
if(serverName.Text.Length == 0)
{
// Initializes the variables to pass to the MessageBox.Show method.
string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if(result == DialogResult.Yes)
{
// Closes the parent form.
this.Close();
}
}
}
Private Sub ValidateUserEntry2()
' Checks the value of the text.
If ServerName.Text.Length = 0 Then
' Initializes variables to pass to the MessageBox.Show method.
Dim Message As String = "You did not enter a server name. Cancel this operation?"
Dim Caption As String = "No Server Name Specified"
Dim Buttons As Integer = MessageBoxButtons.YesNo
Dim Result As DialogResult
'Displays a MessageBox using the Question icon and specifying the No button as the default.
Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
' Gets the result of the MessageBox display.
If Result = System.Windows.Forms.DialogResult.Yes Then
' Closes the parent form.
Me.Close()
End If
End If
End Sub
Kommentarer
Den här uppräkningen används av MessageBox klassen.
Om du inte vill ange ett argument när du anropar metoder på MessageBoxkan du skicka in 0 i stället.