Display a message box and get the message box return value. : MessageBox « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » MessageBoxScreenshots 
Display a message box and get the message box return value.
Display a message box and get the message box return value.
     


<Window x:Class="MessageBoxSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MessageBoxSample" Height="300" Width="500">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"></ColumnDefinition>
      <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
      <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>

    <Label Grid.Column="0" Grid.Row="0">Associate with Owner Window?</Label>
    <CheckBox Grid.Column="1" Grid.Row="0" Name="ownerCheckBox"></CheckBox>

    <Label Grid.Column="0" Grid.Row="1">messageBoxText:</Label>
    <TextBox Grid.Column="1" Grid.Row="1" Name ="messageBoxText">MessageBoxText</TextBox>

    <Label Grid.Column="0" Grid.Row="2">caption:</Label>
    <TextBox Grid.Column="1" Grid.Row="2" Name="caption">Caption</TextBox>

    <Label Grid.Column="0" Grid.Row="3">button:</Label>
    <ComboBox Grid.Column="1" Grid.Row="3" Name="buttonComboBox">
      <ComboBoxItem IsSelected="True">OK</ComboBoxItem>
      <ComboBoxItem>OKCancel</ComboBoxItem>
      <ComboBoxItem>YesNo</ComboBoxItem>
      <ComboBoxItem>YesNoCancel</ComboBoxItem>
    </ComboBox>

    <Label Grid.Column="0" Grid.Row="4">icon:</Label>
    <ComboBox Grid.Column="1" Grid.Row="4" Name="imageComboBox">
      <ComboBoxItem>Asterisk</ComboBoxItem>
      <ComboBoxItem>Error</ComboBoxItem>
      <ComboBoxItem>Exclamation</ComboBoxItem>
      <ComboBoxItem>Hand</ComboBoxItem>
      <ComboBoxItem>Information</ComboBoxItem>
      <ComboBoxItem IsSelected="True">None</ComboBoxItem>
      <ComboBoxItem>Question</ComboBoxItem>
      <ComboBoxItem>Stop</ComboBoxItem>
      <ComboBoxItem>Warning</ComboBoxItem>
    </ComboBox>

    <Label Grid.Column="0" Grid.Row="5">defaultResult:</Label>
    <ComboBox Grid.Column="1" Grid.Row="5" Name="defaultResultComboBox">
      <ComboBoxItem>Cancel</ComboBoxItem>
      <ComboBoxItem>No</ComboBoxItem>
      <ComboBoxItem IsSelected="True">None</ComboBoxItem>
      <ComboBoxItem>OK</ComboBoxItem>
      <ComboBoxItem>Yes</ComboBoxItem>
    </ComboBox>

    <Label Grid.Column="0" Grid.Row="6">options</Label>
    <ComboBox Grid.Column="1" Grid.Row="6" Name="optionsComboBox">
      <ComboBoxItem>DefaultDesktopOnly</ComboBoxItem>
      <ComboBoxItem IsSelected="True">None</ComboBoxItem>
      <ComboBoxItem>RightAlign</ComboBoxItem>
      <ComboBoxItem>RtlReading</ComboBoxItem>
      <ComboBoxItem>ServiceNotification</ComboBoxItem>
    </ComboBox>

    <Button Grid.Column="1" Grid.Row="7" Name="showMessageBoxButton" Click="showMessageBoxButton_Click">Show MessageBox</Button>

    <StatusBar Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="8" >
      <StatusBarItem>
        <TextBlock Name="resultTextBlock">Ready</TextBlock>
      </StatusBarItem>
    </StatusBar>

  </Grid>

</Window>


//File:Window.xaml.vb
Imports System
Imports System.Windows

Namespace MessageBoxSample
  Public Partial Class MainWindow
    Inherits Window
    Public Sub New()
      InitializeComponent()
    End Sub

    Private Sub showMessageBoxButton_Click(sender As Object, e As RoutedEventArgs)
      Dim owner As Window = (If(CBool(ownerCheckBox.IsChecked), Me, Nothing))
      Dim messageBoxText As String = Me.messageBoxText.Text
      Dim caption As String = Me.caption.Text
      Dim button As MessageBoxButton = CType([Enum].Parse(GetType(MessageBoxButton), Me.buttonComboBox.Text), MessageBoxButton)
      Dim icon As MessageBoxImage = CType([Enum].Parse(GetType(MessageBoxImage), Me.imageComboBox.Text), MessageBoxImage)
      Dim defaultResult As MessageBoxResult = CType([Enum].Parse(GetType(MessageBoxResult), Me.defaultResultComboBox.Text), MessageBoxResult)
      Dim options As MessageBoxOptions = CType([Enum].Parse(GetType(MessageBoxOptions), Me.optionsComboBox.Text), MessageBoxOptions)

      Dim result As MessageBoxResult
      If owner Is Nothing Then
        result = MessageBox.Show(messageBoxText, caption, button, icon, defaultResult, options)
      Else
        result = MessageBox.Show(owner, messageBoxText, caption, button, icon, defaultResult, _
          options)
      End If

      resultTextBlock.Text = "Result = " & result.ToString()
    End Sub
  End Class
End Namespace

   
    
    
    
    
  
Related examples in the same category
1.Message Only MessageBoxMessage Only MessageBox
2.MessageBox with Message and HeaderMessageBox with Message and Header
3.Set Message, Header, and Button for MessageBoxSet Message, Header, and Button for MessageBox
4.Customize Message, Header, Button, and Image for MessageBoxCustomize Message, Header, Button, and Image for MessageBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.