I have two forms. My first form is my web browser, the second one is my History form. I would like the user to be able to open the history links in the web browser from my history form. My web browser form has a Navigate method which I use to open pages. I want to use this method in my History form.
Here's my code.
Web Browser Form Navigate Method
private void navigateURL(string curURL )
{
curURL = "http://" + curURL;
// urlList.Add(curURL);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(curURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream pageStream = response.GetResponseStream();
StreamReader reader = new StreamReader(pageStream, Encoding.Default);
string s = reader.ReadToEnd();
webDisplay.Text = s;
reader.Dispose();
pageStream.Dispose();
response.Close();
}
How I call my navigate method within my web browser class
private void homeButton_Click(object sender, EventArgs e)
{
GetHomePageURL();
navigateURL(addressText);
}
So how would I call this method in my second form (History)??
Two methods that occur to me right off the bat...
Raise a method the web browser form listens to. You'd need to declare the event and raise it in the history form whenever the user selects the history entry they want to navigate to:
Then in the web browser form you'd need to add a handler for that event when you create the history form:
If you'll be creating and throwing away multiple history forms make sure you remove your handler (
_historyForm.NavigationRequested -= HistoryForm_NavigationRequested
). It's good practice.Give the history form a reference to the web browser form. When you create the history form, the web browser form would pass it a reference to itself:
new HistoryForm(Me)
... ideally it'd take an interface that has theNavigate
method defined in it. It'd save off that reference and use it to call navigate.