locked
activemdichild in vc++ 2005 RRS feed

  • Question

  • I need to naviagate the webbrowser on the activemdichild.

    In vb.net2005 I succesfully used

    Code Snippet

    dim child as form2 = trycast(form2,activemdichild)

    child.webbrowser1.navigate(combobox1.text)

     

     

    and in c# I used 

    Code Snippet
    Form activeChildForm = this.ActiveMdiChild;

                if (activeChildForm != null)
                {
                    WebBrowser activewebbrowser = (WebBrowser)activeChildForm.ActiveControl;
                    if (activewebbrowser != null)
                        activewebbrowser.Navigate(toolStripComboBox1.Text);
                }

     

     

    SO what do I need to do in vc++2005 to navigate the webbrowser on the activemdichild?
    Thursday, September 13, 2007 6:55 AM

Answers

  • Your C# code is not the same as your VB code.  Using ActiveControl is risky, your browser might not be active.  Try this:

          Form^ frm = this->ActiveMdiChild;
          if (frm != nullptr) {
            for each (Control^ ctl in frm->Controls) {
              WebBrowser^ wb = dynamic_cast<WebBrowser^>(ctl);
              if (wb != nullptr) {
                // Use it...
                // ...
                break;
              }
            }
          }
    Thursday, September 13, 2007 2:12 PM
    Moderator