ARTICLE

WPF CheckBox control in VB.NET

Posted by Rohatash Kumar Articles | XAML in VB.NET February 21, 2011
This article describes how to create and use the checkbox control in WPF using XAML.
Download Files:
 
Reader Level:

CheckBox control

CheckBox control enables the user to select and deselect the associated option. When a checkbox is selected a check (a tick mark) appears indicating a selection. 

Creating CheckBox control in XAML

<CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="10,10,0,0" Name="checkBox1" VerticalAlignment="Top" />

 

The Width and Height property represents the width and the height of the control. Name property represents name of the control. The Header property of TabControl represents the header text of the header.

For example

Addding two CheckBox control, one TextBox and one Button control in XAML.

 

XAML code

 

<CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="10,10,0,0" Name="checkBox1" VerticalAlignment="Top" />

<CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="10,48,0,0" Name="checkBox2" VerticalAlignment="Top" />

<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,95,0,0" Name="button1" VerticalAlignment="Top" Width="75" />

<TextBox Height="23" HorizontalAlignment="Left" Margin="10,153,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />

 

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

 

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles button1.Click

        If checkBox1.IsChecked Then

            textBox1.Text = "Checked"

        ElseIf checkBox2.IsChecked Then

            textBox1.Text = "Unchecked"

        End If

    End Sub

 

Now run the application.


ch1.gif 

Figure1.gif

 

Now select first CheckBox and Click on the Button control.


ch2.gif 

Figure2.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor