Silverlight ProgressBar Control in VB.NET

In this article we will learn how to use ProgressBar control in Silverlight 4.
  • 2287

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

ProgressBar control

ProgressBar control are used to represents the task progress to the user. The Minimum value couldn't be less than 0 and the Maximum one couldn't be more than 100.

Properties - these are the following properties.

pr1.gif

Figure 1.

For example:

Drag a progress control, Button and a label control on the form.

pr2.gif
 

Figure 2.

XAML code:

<UserControl x:Class="SilverlightApplication24.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400"xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"Background="DarkRed">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <ProgressBar Height="34" HorizontalAlignment="Left" Margin="123,75,0,0"Name="ProgressBar1" VerticalAlignment=

                         "Top" Width="171" Foreground="ForestGreen"FontWeight="Bold">

            <ProgressBar.Background>

                <ImageBrush ImageSource="/SilverlightApplication24;component/Images/dog-animal.jpg" />

            </ProgressBar.Background>

        </ProgressBar>

        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="123,142,0,0"Name=

                           "Button1" VerticalAlignment="Top" Width="75" />

        <sdk:Label Height="28" HorizontalAlignment="Left" Margin="250,115,0,0" Name="Label1"VerticalAlignment="Top" Width="120" />

    </Grid>

</UserControl>

 

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

 

Public Sub New()

        InitializeComponent()

    End Sub

    Private Sub DoSomethingHard()

 

        Dim i As Integer = 0

        While i <= 100

 

 

            ProgressBar1.Value = i

 

            Label1.Content = i & "% complete"

            System.Threading.Thread.Sleep(500)

            i = i + 10

        End While

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.Windows.RoutedEventArgs) Handles Button1.Click

        DoSomethingHard()

    End Sub

 

Now save and run the application.


 

pr3.gif

Figure 3. 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.