Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

I am trying to set the ProgressBar.Value to ProgressBar.Maximum >>> Me.ProgressBar.Value = Me.ProgressBar.Maximum

I use this in a thread safe:

   Private Delegate Sub SetFullPrgressCallback()
   Private Sub SetFullPrgress()
       If Me.ProgressBar.InvokeRequired Then
           Dim d As New SetFullPrgressCallback(AddressOf SetFullPrgress)
           Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})
       Else
           Me.ProgressBar.Value = Me.ProgressBar.Maximum
       End If
   End Sub

But I get error, and am not able to troobleshot myself, any help?

Posted

Delegate parameters

 

Your delegate SetFullPrgressCallback does not take any parameters, so you should not be passing any:

 

Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})
'becomes:
Me.Invoke(d)

 

Good luck :cool:

Never trouble another for what you can do for yourself.
Posted

Thank you so much dear friend for all your helps:)

Sorry to take your valuable time, just let me ask my last question:

If I am going to increase the .Value one unit each time:

   Private Delegate Sub SetIncreasePrgressCallback()
   Private Sub SetIncreasePrgress()
       If Me.ProgressBar.InvokeRequired Then
           Dim d As New SetIncreasePrgressCallback(AddressOf SetIncreasePrgress)
           Me.Invoke(d, New Object() {Me.ProgressBar.Value + 1})
       Else
           Me.ProgressBar.Value = Me.ProgressBar.Value + 1
       End If
   End Sub

Where am I wrong?

Thanks.

Posted

For starters, you are going to need to change your delegate and method so that they take an argument.

 

Private Delegate Sub SetIncreasePrgressCallback(byval value as Integer)

and

Private Sub SetIncreasePrgress(byval value as Integer)

My recommendation is to do the following when setting your progress bar's value:

Me.ProgressBar.Value = value

As you can see, it is now trivial to combine the two methods you have mentioned into one pretty easily if you wanted to. Now instead of

Me.Invoke(d, New Object() {Me.ProgressBar.Value + 1})
' or
Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})

you will only have

Me.Invoke(d, New Object() {value})

When you call the method you will pass in either Me.ProgressBar.Maximum or Me.ProgressBar.Value + 1 to this new method that can take any value and set the progress bar accordingly.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...