Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 495
  • Last Modified:

VB 2008 VB.NET Display Animation

Hi,
  I like to have an animation that runs when the program is searching for data, something that shows user that it is functioning.  I do not know how long it will take, so I need something just keeps running.  
   Any one can give me some direction?  

Thanks!
0
KC1688
Asked:
KC1688
  • 4
  • 2
1 Solution
 
shahprabalCommented:
check out :
http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar.aspx

Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
    ' Display the ProgressBar control.
    pBar1.Visible = True
    ' Set Minimum to 1 to represent the first file being copied.
    pBar1.Minimum = 1
    ' Set Maximum to the total number of files to copy.
    pBar1.Maximum = filenames.Length
    ' Set the initial value of the ProgressBar.
    pBar1.Value = 1
    ' Set the Step property to a value of 1 to represent each file being copied.
    pBar1.Step = 1
 
    ' Loop through all files to copy.
    Dim x As Integer
    for x = 1 To filenames.Length - 1
        ' Copy the file and increment the ProgressBar if successful.
        If CopyFile(filenames(x - 1)) = True Then
            ' Perform the increment on the ProgressBar.
            pBar1.PerformStep()
        End If
    Next x
End Sub

Open in new window

0
 
shahprabalCommented:
Also check out :
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/035b622b-2751-4266-99bb-2aa41a3ed6ea
If you want to use the example in the above link you can convert it to vb.net here :
http://www.developerfusion.com/tools/convert/csharp-to-vb/
 
0
 
KC1688Author Commented:
Thanks!  

I tried the progress bar & timer without gathering the data and it worked.  

When the application is getting data, the progress bar and text box become transpart and can not see progress bar moving.  

Please help!!!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
shahprabalCommented:
I think your form is becoming unresponsive... need to use something like this :
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
to run the method that gets the data. If you need help with the code post your code.
0
 
VBRocksCommented:
You can also just set your ProgressBar.Style to Marquee, if you're not able to calculate the progress.

0
 
KC1688Author Commented:
Hi,

  I was hoping I could get it myself, but the ProgressBar Window is still hanging.

  Here is what I like my app to do:
  FormGettingData btnGetData_Click ---> FromGettingData.Enabled = false
  FormProgressBar.show ----> Show ProgressBar running, no need to calculate progress
  Then FormProgressBar go away
  Then FormGettingData  show again
  One additional window FormDoGraph show
 
  I have the following code in the form that tries to get data and I did not post 'get data' code.  I don't know if it affects the whole thing...  Also, my FormDoGraph after the calculation is still haning, not able to display Graph....

Thanks lot lot!


 Private Sub GetData(ByVal worker As BackgroundWorker, ByVal e As DoWorkEventArgs)

        If worker.CancellationPending Then
            e.Cancel = True
        Else

           'Caculations/getting data here
  End Sub


    Private Sub backgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        GetImpData(worker, e)

        If worker.CancellationPending Then
            e.Cancel = True
        End If
    End Sub

    Private Sub backgroundWorker1_RunWorkCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted

        If e.Cancelled Then
            MessageBox.Show("Operation was cancelled")
        ElseIf (e.Error IsNot Nothing) Then
            Dim msg As String = String.Format("An error occurred: {0}", e.Error.Message)
            MessageBox.Show(msg)
        Else
            MessageBox.Show("Operaton was completed")
        End If
    End Sub



    Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetImp.Click
        MeasuringProgressBar.Show()
     

        BackgroundWorker1.RunWorkerAsync()

        Me.Enabled = False


        MeasuringProgressBar.Close()
        Me.Enabled = True
    End Sub
0
 
shahprabalCommented:
Couple of things :
1) After BackgroundWorker1.RunWorkerAsync() the execution of that thread continues, so MeasuringProgressBar.Close will be called before the work is completed. You should move it to RunWorkerCompleted event.
2) I think the main problem could be here :            'Caculations/getting data here
When you are running a separate thread but you try to access the form's control, you need to do it in a specific way. I had trouble understanding it and Chaosian explained it perfectly here :
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22494712.html
 
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now