且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何减少此代码

更新时间:2022-03-07 04:00:55

我不知道VB.net S o使用C sharp



由于WebBrowser1,2,3 ....是对象,你可以创建一个WebBrowser类列表。

like



如果班级在这个结构中



公共类WebBrowser

{



public String Url {get; set;}



public Void Navigate(String path)

{

Url = path;

}

}



你创建了这个类的对象并调用了这样的方法



WebBrowser WebBrowser1 =新的WebBrowse();

WebBrowser WebBrowser2 =新的WebBrowse();







I Don Know VB.net So Using C sharp

Since WebBrowser1,2,3....are objects u can create a list of WebBrowser class.
like

if class is in this structure

Public Class WebBrowser
{

public String Url{get; set;}

public Void Navigate(String path)
{
Url=path;
}
}

you created object of this class and called method like this

WebBrowser WebBrowser1=new WebBrowse();
WebBrowser WebBrowser2=new WebBrowse();
.
.
.
WebBrowser1.Navigate("http://www.google.com.br")
WebBrowser2.Navigate("http://www.google.com.br")









而不是这样的创建列表



List< webbrowser> webBrowserList = new List< webbrowser>();

for(i = 0; i< = 10; i ++)

{

WebBrowser webBrowserObj = new WebBrowser();

webBrowserObj.Navigate( http://www.google.com.br [ ^ ]);

webBrowserList .Add(webBrowserObj);

}


.
.
.
instead of this create list like this

List<webbrowser> webBrowserList=new List<webbrowser>();
for(i=0;i<=10;i++)
{
WebBrowser webBrowserObj=new WebBrowser();
webBrowserObj.Navigate("http://www.google.com.br[^]");
webBrowserList.Add(webBrowserObj);
}


如果我理解正确,那么这是我的解决方案......



如果所有WebBrowser控件都存在于同一容器中(表单,面板,标签条,组控或更多类似控件),则可以使用每个循环

If I Understand Correctly, Then It''s my Solution...

You may Use For Each Loop, If all WebBrowser Controls Present in Same Container (Form, Panel, Tab Strip, Group Control or More Similar Control)
For Each Obj As Object In Form1.Controls
    If TypeOf(Obj) Is WebBrowser Then Obj.Navigate("www.google.com.br")
Next



如果有帮助,请接受此解决方案无论如何......


Accept This Solution if it Help You in anyway...