Click here to Skip to main content
15,886,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form (form1) with a webbrowser which can be opened by many forms. Depending on which form opens this form the webbrowser will open to a different URL.

I tried something like this

VB
If sender Is frmRegInState Then
            Me.WebBrowser1.Url.ToString = ("www.yahoo.com") Then
            frmRegInState.Close()
        ElseIf sender Is frmRegOutOfState Then
            Me.WebBrowser1.Url.ToString = ("www.google.com") Then
            frmRegOutOfState.Close()
        End If
Posted
Comments
[no name] 15-Aug-12 15:14pm    
Okay good for you! Thanks for keeping us up to date on your progress.

1 solution

Create an interface with a url property like this :
C#
public interface IUrlOwner
    {
        Uri Url
        {
            get;
            set;
        }
    }


Then make your form implement this interface. So the form will know which url to open.
like this :
public partial class DrawingWindow : Form,IUrlOwner 

Of course you have to implement the interface. so you need a concrete getter and setter.
Then you can cast the sender to the interface and get to the url in your event handler.
C#
(sender as IUrlOwner)Url


My code is more like C# but I hope you know enough about VB.NET to understand what is going on here.
 
Share this answer
 
v2
Comments
Abdul Quader Mamun 15-Aug-12 21:40pm    
good Work!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900