internet explorer control

Apr 7 2009 5:41 PM
I have made a little program that when i open the IE and puts url google.com i should go to microsoft.com for exemple in the same window, but it opens a new ie windows and goes to the site can someone help.

the code

detect new ie open
 private void Form1_Load(object sender, EventArgs e)
        {
            shellWindows.WindowRegistered += new SHDocVw.DShellWindowsEvents_WindowRegisteredEventHandler(detect_ie);
                    
        }

private void detect_ie(int z)
        {
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {

                ie.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(ie_BeforeNavigate2);



            }
     
        }



Detects the url open and goes to new url

               
                 void ie_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
        {

            object Flags2 = Flags;
            object TargetFrameName2 = TargetFrameName;           
            ur=URL.ToString();
       
            int tamanho =0;
            int cont =0;
            while (cont < 3)
            {
                tamanho = tamanho + 1;
                if (ur[tamanho] == '/')
                {
                    cont = cont + 1;
                }
            }
            ur = ur.Substring(0, tamanho);
           
            if (ur == "www.microsoft.com")
            {
                URL="www.google.com";
                SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
                URL = "www.google.com".ToString();
                ie.Navigate2(ref URL, ref Flags, ref TargetFrameName, ref PostData, ref Headers);
            }
         
          }

Answers (1)