How do make progress bar work on the working interface?

Hi,

I am programming two interfaces for a Windows application: interface1 is the main interface, and there is a button on it. When I click the button on the interface1, the interface2 should be shown. But it will take long time to display the interface2 (the working interface), since the interface2 is doing many computings. I would like to set a progress bar so that the interface2 can display immediately after I click the button on the interface1. After the interface2 display, we can see the progress growing step by step. Could anyone provide a sample program Thanks in advance.

Moreover, I use the following codes to make the interface2 display:

Private Sub ButtonEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEdit.Click

interface2.Show(Me)

End Sub




Answer this question

How do make progress bar work on the working interface?

  • guptasameer1984

    Be careful with you wording as I am using when you refer to interface you are in probably refering to User Interface (or form).

    From what you are talking about it would appear that you want to update a control on another form. This is fairly easy to achieve but you need to create a reference on one form to the other.

    So an example here would be to create a windows application with two forms. Form1 will have two buttons on and form2 will have a label on called Form1

    Public Class Form1

    Private childform As Form2

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim ObjChild As New Form2
    ObjChild.Show()
    childform = ObjChild
    End Sub

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

    With childform
    .Label1.Text = .Label1.Text & "1"
    End With
    End Sub
    End Class

    Form1 is the startup form and by clicking button2 you will create an instance of form2 and set a reference on form1 called childform which will allow me to call methods, set properties etc. on this instance.

    So once the form is up I click on Button1 and it will add the character1 to the label on form2.

    Nothing amazing but it shows the general concept of one form referring to another form. In you example Instead of setting the label1.text property you will probably be setting the progressbar control value and visible properties.


  • Gerry Fan

    The advice you've been given is correct, but I'd use a delegate to loosely couple the two forms together, rather than having a copy of one form in another. This forces you to not make UI components public, which may otherwise be a temptation, and generally provides for better seperation between classes.

    http://abstractvb.com/code.asp A=1084

    That's a good link on how delegates work.



  • brakermb19

    Agreed, delegates is probably a more efficient way of handling this.

    Also I'm inclined that if its such a long running process that a background worker may be also required in which case getting the backgroundworker process to update UI invariably requires delegates.

    http://msdn2.microsoft.com/en-us/library/b2zk6580.aspx

    shows how to use background worker and report progress.


  • How do make progress bar work on the working interface?