Silverlight CheckBox control in VB.NET

In this article we will learn how to use CheckBox control in Silverlight.
  • 1883

In this article we will learn how to use CheckBox control in Silverlight.

CheckBox control

The CheckBox control is used to display a check box. The CheckBox control gives us an option to select true/false. A checkbox is clicked to select and clicked again to deselect some option. When a checkbox is selected, a check (a tick mark) appears indicating a selection.



Figure 1.

Content - show the  text  shown with the CheckBox.

IsChecked: Specifies whether the check box is checked or not.

CheckBox event:

Private Sub CheckBox1_Checked(ByVal sender As System.ObjectByVal e AsSystem.Windows.RoutedEventArgs

Handles CheckBox1.Checked

End Sub

For example:

Drag two CheckBoxes, a TextBox and a Button control on to the form. Set the Text property for the CheckBoxes as Male and Female. The following code will display the text of the Checkbox that is checked in the textbox when the button is clicked. Form looks like this:


Figure 2.

XAML code:

<UserControl x:Class="SilverlightApplication9.MainPage"





    mc:Ignorable="d" Height="432" Width="609">

    <Canvas Height="344" Name="Canvas1" Width="372" Cursor="None">

        <CheckBox Canvas.Left="14" Canvas.Top="16" Height="23" Name="CheckBox1"Content="Male" FontSize="16" Width="69" />

        <TextBox Canvas.Left="97" Canvas.Top="16" Height="23" Name="TextBox1" Width="120" />

        <Button Canvas.Left="123" Canvas.Top="55" Content="Button" Height="23" Name="Button1"Width="75" />

        <CheckBox Canvas.Left="12" Canvas.Top="55" Content="Female" Height="16"Name="CheckBox2" FontSize="14" />





Now double click on the button control and add the following code.

Private Sub Button1_Click(ByVal sender As System.ObjectByVal e AsSystem.Windows.RoutedEventArgsHandles Button1.Click

        If CheckBox1.IsChecked Then

            TextBox1.Text = "Your Gender: mail"

        ElseIf CheckBox2.IsChecked Then

            TextBox1.Text = "Your gender: Femail"

        End If


    End Sub


Now save and run the application.


Figure 3.


More Articles

© 2020 DotNetHeaven. All rights reserved.