2

I am creating new IE browser instance dynamically, and opening a aspx page from there. Everything works fine , but the browser is not popping in the Front of the screen .Able to see the Aspx page in the task bar when I click it from there it comes to the Front . How to bring that page in front of all the Screen as soon as IE is created.

I have pasted the code I used to create new IE instance.

public class IEInstance
{
    public SHDocVw.InternetExplorer IE1;
    public void IEInstanceCls(string check)
    {
        IE1 = new SHDocVw.InternetExplorer();
        object Empty = 0;
        string urlpath = " ";            
        urlpath = "http://localhost/TestPage.aspx?";         
        object URL = urlpath;
        IE1.Top = 260;
        IE1.Left = 900;
        IE1.Width = 390;
        IE1.Height = 460;
        IE1.StatusBar = false;
        IE1.ToolBar = 0;
        IE1.MenuBar = false;
        IE1.Visible = true;
        IE1.Navigate2(ref URL, ref Empty, ref Empty, ref Empty, ref Empty);
    }
}

Help me to solve this problem.

Thank You

Rohit Vipin Mathews
  • 11,629
  • 15
  • 57
  • 112
Parameswari
  • 69
  • 1
  • 7

1 Answers1

4

The Internet explorer object has an HWND property, which is the handle to a window. You can use that to bring the window to the front like:

    SetForegroundWindow((IntPtr)IE1.HWND);

You'll need to import SetForgroundWindow windows API like this near the top of your file.

    [DllImport("user32.dll")]
    static extern bool SetForegroundWindow(IntPtr hWnd);
jm.
  • 23,422
  • 22
  • 79
  • 93