2 Replies - 657 Views - Last Post: 01 April 2012 - 04:17 PM Rate Topic: -----

#1 Manvaril  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 31-March 12

making the webbrowser navigate after saving settings from child form/d

Posted 31 March 2012 - 04:37 PM

I have a child settings form that you put a url into a text box, on closing the settings form it saves the url to the settings file and then I can't get it to navigate the webbrowser object on the parent form to goto the saved URL. I have looked around for an example on how to pass the URL to the parent form and can't find one. There are plenty of examples on how to do it via MDI but that don't help me in my case.

Here is what I have.
        private void btnSave_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.setting_poladdress = txtbPOWebPath.Text;
            Properties.Settings.Default.setting_startwin = cheStartWin.Checked;
            Properties.Settings.Default.Save();
            Close();
            mnView mainParent = (mnView)Parent;
            mainParent.webBrowser.Navigate(Properties.Settings.Default.setting_poladdress);
        }



ERRORS:
-Use the "new" to create an object instance.
-Check to determine if the object is null before calling the method.

Is This A Good Question/Topic? 0
  • +

Replies To: making the webbrowser navigate after saving settings from child form/d

#2 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

Re: making the webbrowser navigate after saving settings from child form/d

Posted 01 April 2012 - 06:30 AM

Have you placed breakpoints and stepped through your code to see if any objects are null?

Have you declared an object without initializing it with the "new" keyword? Check each place where you declare an object instance.

Those error messages are self explanatory and accurate.

This post has been edited by negligible: 01 April 2012 - 06:32 AM

Was This Post Helpful? 0
  • +
  • -

#3 Manvaril  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 31-March 12

Re: making the webbrowser navigate after saving settings from child form/d

Posted 01 April 2012 - 04:17 PM

Well I was able to fix my problem, took me quite a while but after a lot of tries and a lot of failures and a lot of frustration I figured it out. My problem was that I had not put in a hook into the Parent Form so the Child Form didn't know who it's parent was.

I was missing a "this" in the Parent Form like this:
        private void mnuSettings_Click(object sender, EventArgs e)
        {
            mnSettings ShowSettings = new mnSettings();
            ShowSettings.ShowDialog(this);
        } 



And I was missing some key parts in calling the Parent Form with my original code:

        private void btnSave_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.setting_poladdress = txtbPOWebPath.Text;
            Properties.Settings.Default.setting_startwin = cheStartWin.Checked;
            Properties.Settings.Default.Save();
            this.Close();
            if (cheStartWin.Checked == true)
            {
                RegistryKey rkapp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                rkapp.SetValue("PizzaOnlineConsole_Startup", Application.ExecutablePath.ToString());
            }
            if (cheStartWin.Checked == false)
            {
                RegistryKey rkapp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                rkapp.DeleteValue("PizzaOnlineConsole_Startup", false);
            }
            mnView mainParent = (mnView)this.Owner;
            mainParent.webBrowser.Navigate(Properties.Settings.Default.setting_poladdress);
        }



Needless to say it was a number of factors that prevented my form from sending the URL to the browser.
There are a lot of posts on the internet about Parent to Child communication but very very few in Child to Parent communication. This is an example of Child to Parent communication.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1