这是在C#
所以我正在尝试为多个webBrowser控件创建一个ProgressChanged事件。这些都是动态创建的以及进度条。所以我不能事先打电话给它。我正在做的是通过运行的对象数组传递进度条。它最终进入我创建浏览器的最终方法,需要创建Browser.ProgressChanged事件。
这是代码....
private object[] runTests(string banText, object tabControlName,
object progressBar, int runThisTest, string testName)
{
object[] theReturn = null;
if (stopTests == false)
{
var tabPageBrowser = new TabPage();
var Browser = new WebBrowser();
(tabControlName as TabControl).TabPages.Add(tabPageBrowser);
tabPageBrowser.Name = tabControlName.ToString();
if (banText == "999999999")
{
tabPageBrowser.Text = "History";
}
else
{
tabPageBrowser.Text = testName;
}
tabPageBrowser.Font = new System.Drawing.Font("Trebuchet MS", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
Browser.Dock = DockStyle.Fill;
Browser.Url = new Uri(testStrings(runThisTest, banText));
Browser.Name = tabControlName.ToString();
Browser.ScriptErrorsSuppressed = true;
tabPageBrowser.Controls.Add(Browser);
Browser.ProgressChanged += new WebBrowserProgressChangedEventHandler(Browser_ProgressChanged);
try
{
while (Browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
catch
{
return null;
}
IntPtr pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);
object[] browserObjects = new object[2];
browserObjects[0] = tabPageBrowser;
browserObjects[1] = Browser;
if(browserObjects != null)
{
theReturn = browserObjects;
}
}
return theReturn;
}
现在我的问题是,当我创建事件时如何添加“progressBar”对象,以便我可以在事件被触发时调用它。我基本上是为5个以上的WebBrowser控件创建一个进度条,并将它们的进度链接在一起。所以出于某种原因,我试图将对象添加到方法中,但它失败了。请帮助和谢谢!
答案 0 :(得分:1)
Browser.ProgressChanged += Browser_ProgressChanged;
...
void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
if (e.MaximumProgress > 0) {
int prog = (int)(100 * e.CurrentProgress / e.MaximumProgress);
progressBar1.Value = prog;
}
}
private ProgressBar progressBar1;