ARTICLE

WPF Button control in VB.NET

Posted by Micalgray Articles | XAML in VB.NET February 23, 2011
Here we see how to create Button control and also explains basic use of the Button control.
Download Files:
 
Reader Level:

Here we see how to create Button control and also explains basic use of the Button control in xaml.

Button control

The Button control allows the user to click it to perform an action. The Button control display with text and image.

Creating a Button in XAML
 

The Button element represents a WPF Button control in XAML.

 
<Button Content="Button" Height="29" Name="Button1" Width="200" />

 

The Width and Height attributes of the Button element represent the width and the height of a Button. The Content property of the Button element sets the text of a button. Name attribute represents the name of the control, which is a unique identifier of a control.

 

im1.gif

Figure1.gif

 

Important Properties - These are the important properties of the Button control.

Width - Width property represents the width of a Button.

Height - Height property represents the height of a Button.

Content - The text shown on the button.

Command - Gets or sets the command to invoke when this button is pressed.

CommandParameter - CommandParameter is used to pass parameter to the Command property.

ClickMode - Gets or sets when the Click event occurs.

 

For example

 

creating two text boxes, one to input (Label) a number and other to output (Label)a number and a Buttons.

 

XAML code

 

<Label Content="Number" Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="Label1" VerticalAlignment="Top" />

        <Label Content="Result" Height="28" HorizontalAlignment="Left" Margin="10,48,0,0" Name="Label2" VerticalAlignment="Top" />

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

        <TextBox Height="23" HorizontalAlignment="Left" Margin="74,48,0,0" Name="txtResult" VerticalAlignment="Top" Width="120" />

     <Button Content="Cube" Height="23" HorizontalAlignment="Left" Margin="74,96,0,0" Name="cmdSquare" VerticalAlignment="Top" Width="141" Background="red" />

 

Now the above code control looks like this.

 

im2.gif

Figure2.gif

 

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

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

        Dim num As Double = Double.Parse(txtNumber.Text)

        Dim cu As Double = num * num * num

        txtResult.Text = cu.ToString()

    End Sub

Now run the application.

im3.gif

Figure3.gif

Now enter the value in the input box.

im4.gif

Figure4.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    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!
Team Foundation Server Hosting
Become a Sponsor