שתף באמצעות


Making a ProgressBar load on the click of a specific button.

Question

Thursday, March 28, 2013 12:28 PM

First off excuse me if there is already a thread covering this out there. I am new to VB however not new to C++ although that isnt the point. I would like to know how to make a pogress bar start loading on a click of a button. 

So on the click of the "Login button" which name is Button1 or something similar, i want the progress bar to start to load. Not its actual progress but the time i have set it to run. Note: The ProgressBar works but MVS set it to run as soon as the program runs without any user interaction whatsoever.

So an over all review is how can i get the ProgressBar to start loading on the user clicking the button? 

All replies (3)

Thursday, March 28, 2013 2:36 PM ✅Answered

Hi,

This is a simple example of making a progressbar advance with a timer after pressing a button. Create a new project and add 1 progressbar, 1 button, and 1 timer. Then add this code.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'These can be set in the controls properties in the designer if you don`t want to do it in code
        Timer1.Enabled = False
        Timer1.Interval = 100
        ProgressBar1.Value = 0
        ProgressBar1.Maximum = 100
        ProgressBar1.Step = 1
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ProgressBar1.Value = 0
        Timer1.Start()
        Button1.Enabled = False
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value += 1
        If ProgressBar1.Value = 100 Then
            Timer1.Stop()
            Button1.Enabled = True
        End If
    End Sub
End Class

Thursday, March 28, 2013 12:34 PM

This is in fact a windows form or WPF question. 

Both have a progressbar with properties which tell the start, the progress and the end. 

Those 3 properties have to be set. Be aware the progressbar is not something that runs on its own.

Success
Cor


Thursday, March 28, 2013 12:36 PM

Well i added a timer. Other than that i didnt do anything to it to make it start on the opening on the application. So i should repost this in the WPF forums?