Click here to Skip to main content
15,846,346 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

I am trying to open an IE window from my code using the following:
private void Form1_Load(object sender, EventArgs e)
{
       object sObj = null;
       m_IExplorer = new SHDocVw.InternetExplorerClass();
       m_WebBrowser = (IWebBrowserApp)m_IExplorer;
            
       object sUrl = "www.google.com";
       m_WebBrowser.Navigate((string)sUrl, ref sObj, ref sObj, ref sObj, ref sObj);
       m_WebBrowser.Visible = false;
       int mainHandle = m_IExplorer.HWND;
}

and then in a button click I am opening a new window like this:
private void button1_Click(object sender, EventArgs e)
{
 object flag = 0x1;
 object sObj = null;
 object sUrl = "http://www.yahoo.com";
 m_WebBrowser.Navigate((string)sUrl, ref flag, ref sObj, ref sObj, ref sObj);
 m_WebBrowser.Visible = true;
 int childHandle = m_IExplorer.HWND;
}

So here, at the form load my main window, I intend to have it invisible and only make the child window visible. But what happens is, at the button click when the child window is made visible, both the main and the child window becomes invisible.

What I would like to know is how do I get the handle on the new window that is created and just try to make that visible and keep the main window visible property as false.

Thanks for your help,
-Bhaskar.
Posted
Updated 13-Mar-11 22:27pm
v2
Comments
JF2015 14-Mar-11 3:27am    
Added code formatting.

1 solution

I have found a solution to this problem. In the button click I just have to remove the line:

m_WebBrowser.Visible = true;

The navigate command by default opens up a visible page and there is no explicit need to make it visible. Doing it explicitly makes both the windows visible.

Thanks,
-Bhaskar
 
Share this answer
 

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

  Print Answers RSS


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