Reputation: 225
I am currently working on a app that has multi web browsers on a tab control with progress bars on them. To save me duplicating code i wanted to create a method where i pass the progress bar name into a function. I have created the following below but i am getting this error.
'string' does not contain a definition for 'Maximum' and no extension method 'Maximum' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
private void PassPBName(string PBName)
{
// Event for the browser
AxSHDocVw.DWebBrowserEvents2_ProgressChangeEvent e;
/* The CurrentProgress variable from the raised event
* gives you the current number of bytes already downloaded
* while the MaximumProgress is the total number of bytes
* to be downloaded */
if (e.progress < e.progressMax)
{
// Check if the current progress in the progress bar
// is >= to the maximum if yes reset it with the min
if (PBName.Value >= PBName.Maximum)
PBName.Value = PBName.Minimum;
else
// Just increase the progress bar
PBName.PerformStep();
}
else
// When the document is fully downloaded
// reset the progress bar to the min (0)
PBName.Value = PBName.Minimum;
}
private void WBIntranet_ProgressChange(object sender, AxSHDocVw.DWebBrowserEvents2_ProgressChangeEvent e)
{
string progressBar = PBIntranet.Value.ToString();
PassPBName(progressBar);
}
Thanks
Upvotes: 1
Views: 3719
Reputation: 225
I found the solution if anyone else wants to know how to do this.
private void PassPBName(ToolStripProgressBar PBName, AxSHDocVw.DWebBrowserEvents2_ProgressChangeEvent e)
{
/* The CurrentProgress variable from the raised event
* gives you the current number of bytes already downloaded
* while the MaximumProgress is the total number of bytes
* to be downloaded */
if (e.progress < e.progressMax)
{
// Check if the current progress in the progress bar
// is >= to the maximum if yes reset it with the min
if (PBName.Value >= PBName.Maximum)
PBName.Value = PBName.Minimum;
else
// Just increase the progress bar
PBName.PerformStep();
}
else
// When the document is fully downloaded
// reset the progress bar to the min (0)
PBName.Value = PBName.Minimum;
}
private void WBIntranet_ProgressChange(object sender, AxSHDocVw.DWebBrowserEvents2_ProgressChangeEvent e)
{
//Pass the PB bar name to PassPBName function to show current progress.
PassPBName (PBIntranet, e);
}
Upvotes: 0
Reputation: 38526
You can't reference an object by just having it's name in a variable. You would have to access it through Reflection. Something like this:
Using System.Reflection;
ProgressBar myProgress = (ProgressBar)this.GetType().GetField(PBName).GetValue(this);
I am a little sketchy on the syntax, but maybe this will help push you further along. Once you have the actual object, then you can access the Maxmimum/Minimum/etc.
Upvotes: 0
Reputation: 9006
You have a string named PBName
, but you are using it as if it were a progress bar class. Perhaps you meant to pass the class in? Assuming that PBIntranet
is the actual progess bar class, it looks like you should be passing that into your PassPBName
function. Just guessing, you also need to pass in e
from your WBIntranet_ProgressChange
event as well, not locally declare another in PassPBName
, which I don't think will work as you intend.
Upvotes: 1
Reputation: 700740
If you send the name of the progressbar, you need to use something like the FindControl method to find the control. It's better if you send a reference to the progressbar control instead:
private void PassPBReference(ProgressBar PBName) {
...
}
and call it using just:
PassPBReference(PBIntranet);
(You should of course make up a better name for the method, that reflects what it does and not just how you pass the parameters to it.)
Upvotes: 1