ADO DOT NET Posted February 14, 2007 Posted February 14, 2007 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? Quote
MrPaul Posted February 14, 2007 Posted February 14, 2007 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: Quote Never trouble another for what you can do for yourself.
ADO DOT NET Posted February 14, 2007 Author Posted February 14, 2007 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. Quote
mskeel Posted February 14, 2007 Posted February 14, 2007 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.