Saturday 14 September 2013

VB.Net - ProgressBar Control

It represents a Windows progress bar control. It is used to provide visual feedback to your users about the status of some task. It shows a bar that fills in from left to right as the operation progresses.
Let's click on a ProgressBar control from the Toolbox and place it on the form.
VB.Net ProgressBar Control
The main properties of a progress bar are ValueMaximum and Minimum. The Minimum and Maximum properties are used to set the minimum and maximum values that the progress bar can display. The Value property specifies the current position of the progress bar.
The ProgressBar control is typically used when an application performs tasks such as copying files or printing documents. To a user the application might look unresponsive if there is no visual cue. In such cases, using the ProgressBar allows the programmer to provide a visual status of progress.

Properties of the ProgressBar Control

The following are some of the commonly used properties of the ProgressBar control:
S.NPropertyDescription
1AllowDropOverrides Control.AllowDrop.
2BackgroundImageGets or sets the background image for the ProgressBar control.
3BackgroundImageLayoutGets or sets the layout of the background image of the progress bar.
4CausesValidationGets or sets a value indicating whether the control, when it receives focus, causes validation to be performed on any controls that require validation.
5FontGets or sets the font of text in the ProgressBar.
6ImeModeGets or sets the input method editor (IME) for the ProgressBar.
7ImeModeBaseGets or sets the IME mode of a control.
8MarqueeAnimationSpeedGets or sets the time period, in milliseconds, that it takes the progress block to scroll across the progress bar.
9MaximumGets or sets the maximum value of the range of the control.
10MinimumGets or sets the minimum value of the range of the control.
11PaddingGets or sets the space between the edges of a ProgressBar control and its contents.
12RightToLeftLayoutGets or sets a value indicating whether the ProgressBar and any text it contains is displayed from right to left.
13StepGets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar.
14StyleGets or sets the manner in which progress should be indicated on the progress bar.
15ValueGets or sets the current position of the progress bar.

Methods of the ProgressBar Control

The following are some of the commonly used methods of the ProgressBar control:
S.NMethod Name & Description
1Increment 
Increments the current position of the ProgressBar control by specified amount.
2PerformStep
Increments the value by the specified step.
3ResetText
Resets the Text property to its default value.
4ToString
Returns a string that represents the progress bar control.

Events of the ProgressBar Control

The following are some of the commonly used events of the ProgressBar control:
S.NEventDescription
1BackgroundImageChangedOccurs when the value of the BackgroundImage property changes.
2BackgroundImageLayoutChangedOccurs when the value of the BackgroundImageLayout property changes.
3CausesValidationChangedOccurs when the value of the CausesValidation property changes.
4ClickOccurs when the control is clicked.
5DoubleClickOccurs when the user double-clicks the control.
6EnterOccurs when focus enters the control.
7FontChangedOccurs when the value of the Font property changes.
8ImeModeChangedOccurs when the value of the ImeMode property changes.
9KeyDownOccurs when the user presses a key while the control has focus.
10KeyPressOccurs when the user presses a key while the control has focus.
11KeyUpOccurs when the user releases a key while the control has focus.
12LeaveOccurs when focus leaves the ProgressBar control.
13MouseClickOccurs when the control is clicked by the mouse.
14MouseDoubleClickOccurs when the user double-clicks the control.
15PaddingChangedOccurs when the value of the Padding property changes.
16PaintOccurs when the ProgressBar is drawn.
17RightToLeftLayoutChangedOccurs when the RightToLeftLayout property changes.
18TabStopChangedOccurs when the TabStop property changes.
18TextChangedOccurs when the Text property changes.

Example

In this example, let us create a progress bar at runtime. Let's double click on the Form and put the follow code in the opened window.
Public Class Form1
   Private Sub Form1_Load(sender As Object, e As EventArgs) _
      Handles MyBase.Load
      'create two progress bars
      Dim ProgressBar1 As ProgressBar
      Dim ProgressBar2 As ProgressBar
      ProgressBar1 = New ProgressBar()
      ProgressBar2 = New ProgressBar()
      'set position
      ProgressBar1.Location = New Point(10, 10)
      ProgressBar2.Location = New Point(10, 50)
      'set values
      ProgressBar1.Minimum = 0
      ProgressBar1.Maximum = 200
      ProgressBar1.Value = 130
      ProgressBar2.Minimum = 0
      ProgressBar2.Maximum = 100
      ProgressBar2.Value = 40
      'add the progress bar to the form
      Me.Controls.Add(ProgressBar1)
      Me.Controls.Add(ProgressBar2)
      ' Set the caption bar text of the form.  
      Me.Text = "tutorialspoint.com"
   End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show following window:
Progress Bar Example

No comments:

Post a Comment