Webbrowser controls the new window

Source: Internet
Author: User
When the page is displayed as a new window, the following Code Demonstrate how to load the page in the new form and the Web Control of the current form to load the form

1. Create a new form, which should be known to most people. You can use newwindow2, but the vs2005 web control is encapsulated by Ms. Pay attention to it.

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. reflection;
Namespace windowsapplication24

Public partial class form1: Form
{< br>
Public form1 ()
{< br> initializecomponent ();
This. webbrowser1.navigate ("about: blank");
(this. webbrowser1.activexinstance as shdocvw. webbrowser ). newwindow2 + = new shdocvw. dwebbrowserevents2_newwindow2eventhandler (form1_newwindow2);

}
Private void button#click (Object sender, eventargs E)
{
This. webbrowser1.navigate ("www.google.cn ");
}

Void form1_newwindow2 (ref object ppdisp, ref bool cancel)
{
Form1 FRM = new form1 ();
Ppdisp = FRM. webbrowser1.activexinstance;
FRM. Show ();
}


}
}

2. Load directly in the Web Control of the current form. This requires the newwindow3 event.

using system;
using system. collections. generic;
using system. componentmodel;
using system. data;
using system. drawing;
using system. text;
using system. windows. forms;
using system. reflection;
namespace windowsapplication24
{< br> Public partial class form1: Form
{< br>
Public form1 ()
{< br> initializecomponent ();
This. webbrowser1.navigate ("about: blank");
(this. webbrowser1.activexinstance as shdocvw. webbrowser ). newwindow3 + = new shdocvw. dwebbrowserevents2_newwindow3eventhandler (form1_newwindow3);

}

Void form1_newwindow3 (ref object ppdisp, ref bool cancel, uint dwflags, string bstrurlcontext, string bstrurl)
{
Cancel = true;
This. webbrowser1.navigate (bstrurl );
}
Private void button#click (Object sender, eventargs E)
{
This. webbrowser1.navigate ("www.google.cn ");
}


}< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.