使用对象创建新事件
这是在 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 控件创建一个进度条,并将它们的进度链接在一起。因此,出于某种原因,我尝试将对象添加到方法中,但它失败了。请协助并谢谢!
This is in C#
So I'm trying to create an event for ProgressChanged for multiple webBrowser Controls. These are all dynamically created as well as the progress bar. So i can't call upon it prior. What i'm doing is passing the progress bar through object arrays that are ran. It finally gets to the final method in which i create the browser and need to create the Browser.ProgressChanged event.
Here's the code....
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;
}
Now my question is, how can I add the "progressBar" object when i create the event so i can call upon it when the event has been fired. I'm basically creating a single progress bar for 5+ WebBrowser controls and linking the progress of them together. So for some reason i tried to add the object to the method and it fails out on me. Please assist and Thanks!.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)