c# - passing url from a form to a different form which contains web browser control -
i'm trying pass url 1 form form (both in same project).
the first form contains web browser control in it. has button, on press of button second form launches. second form has button hard coded url. when user clicks on button url should passed first form , webbrowser should navigate link. below simple code i'm trying
form1:
public partial class form1 : form { public form1() { initializecomponent(); } public void loadwebpage(string link) { webbrowser1.navigate(link); } private void button1_click(object sender, eventargs e) { secondform form2 = new secondform(); form2.show(); } } form2:
public partial class secondform : form { public secondform() { initializecomponent(); } private void button1_click(object sender, eventargs e) { this.close(); form1 form1= new form1(); form1.loadwebpage("http://www.google.com"); } } the above code not working, webbrowser control not navigate google page. can
send first form parameter second form. on second form, create property on class matches type of first form.
in constructor of second form, set said property.
when user clicks button on second form, reference property of class has been set instance of first form , call loadwebpage function.
edit:
public partial class form1 : form { public form1() { initializecomponent(); } public void loadwebpage(string link) { webbrowser1.navigate(link); } private void button1_click(object sender, eventargs e) { secondform form2 = new secondform(this); form2.show(); } } form 2:
public partial class secondform : form { public form1 form1 { get; set;} public secondform(form1 f) { form1 = f; initializecomponent(); } private void button1_click(object sender, eventargs e) { this.close(); form1.loadwebpage("http://www.google.com"); } }
Comments
Post a Comment