TabControl

xiaoxiao2021-03-06  18

http://www.microsoft.com/china/msdn/library/langtool/vcsharp/overvwwebbrowexp.mspx

Welcome to MSDN>

Development language and tools

Web Browser Express Overview

Release Date: 8/26/2004

| Update Date: 8/26/2004

John kennedy

Microsoft Corporation

Summary: Create your own, support tab web browser, and connect to the search engine integrated link.

Download WebBrowseRexpress.msi sample files.

This page

Introduction to the benefits of using others to design Web browser work principle What is interesting?

Introduction

One of the web browser is to open different tabs or subpages in the same browser window, which is getting more popular. When you browse multiple sites, use tabs to separate multiple pages to keep your desktop neat. There are several third-party web browsers that provide this feature on Windows and other platforms. If you are like me, you will find this is an addictive browsing method. Many browsers, whether default settings or through plugins, there is also a quick way to perform web searches without using search engines. Ability to write your own browser and make it possible to complete all of these work, you can also fine tune it and adjusted to your needs, isn't it great?

Figure 1: Design and implement your own web browser with Visual C # Express

It seems that it takes a lot of work as if you look like a new product. After all, how long does developing Internet Explorer? (A: For a long time.) How can I use only one night, a single-gun horse, can copy the powerful HTML rendering function of Internet Explorer and add my own new function list? That's because I use Visual C # Express.

Back to top

The benefits of using others

The secret to write a web browser in one night is the use of other people. In this example, the secret is used to use the C # Express WebBrowser control. If you have installed C # Express and open your help, you may have seen a name called. ° How to create a Windows application with C # Express ± topic. This short project will guide you through the various steps involved in creating a Windows Form application. If you haven't finished reading yet, and you are not familiar with C #, I suggest you read it.

The key is that it is easy to create multiple applications (including a complete web browser) by using controls with C # Express. Once the WebBrowser control is already on the Windows form, you just tell it which URL is to get and display, and whether you need to return, forward, refresh or stop. Connecting to the Internet, obtain data, format HTML, all difficulties such as HTML, display graphics, are processed by the control.

This project is similar to the help project, except for a point, the project creates multiple webbrowser controls and adds it to the web page in TabControl, not only to add a WebBrowser control to the Windows form. Yes, I don't even need to write code to create TabControl. This is another example of dragging from the toolbox to the Windows Form.

Then, although I know that this seems to have a huge and complex app, it seems that it takes a few months of work to complete, but in fact I just connected the point between existing controls, just completed all the work at night. This is my programming way!

Back to top

Design Web Browser Figure 2: Drag the control from the toolbox is the key to writing this app

The following describes how I started to create a Web Browser Express project. After creating a Windows application from the C # Express New Project dialog box, I drag the following controls to the Windows Form:

TABControl: This control stores all subpages, each of which controls a webbrowser control. Once it has been created, it will be easy to add other pages to it. To determine which the entire Windows form is filled, the Dock property is set to Fill. This allows the control to keep the same size as the Windows form, even if it is adjusted. 2. MeNustrip: Although there is no menu in this application, there is a region, buttons, and text boxes, buttons, and text boxes can be added to this area. Also, if you decide to add some menu options, you can add it here. I dragged Menustrip so that it became slightly. 3.Buttons: There are some simple controls for web browsing. The button is dragged into the menustrip and resize, and an image is applied to these buttons. One thing I need to do is to re-draw the image background, making it light blue to look like Menustrip. 4.TextBoxes and ComboBoxes: In addition to the button, I also need a text box for URL and search strings. In fact, the URL is a ComboBoxes that allows the user to enter a web address and select a project from a drop-down list. This list is filled in the designer, but if you want, you can add new items in programming. 5.Picturebox: The homemost PictureBox control is used for decoration. Web browser displays some animations when downloading. 6.Timer: Timer object is used for a second to issue a message. This message is captured by a method called Timer1_Tick () and is used to change the image displayed in Picturebox. The result is an animation. This is not a first-stream solution, but it works.

Back to top

working principle

When the program is started, the first thing it does is to call CREATE_A_NEW_TAB (). This method creates a new tab page to add it to TabControl and create a webbrowser control on it. WebBrowser URL is set to "Home", no matter what it may be on your system. Below is the code that creates a new tab:

// Create a new tab page

TabPage NewPage = New Tabpage ("Loading ...");

TabControl1.tabpages.Add (NewPage);

This is the code that creates a new webbrowser control:

// CREATE A New WebBBROWSER CONTROL.

Webbrowser WebPage = New WebBrowser ();

WebPage.Parent = newpage;

WebPage.dock = DockStyle.Fill;

WebPage.DocumentCompleted = new webbrowserdocumentCompletedEventHandler (webPage_DocumentCompleted);

Webpage.gohome ();

This code determines that the parent of WebBrowser is a TAB page. It also uses a Dock set to Fill to determine that it is also maintained at the actual size of the window. We also added an event handler: The control works by sending the message to your program. You can choose the message you listening, and the method that is called by the event handler link to the message. In this example, the message tells us that WebControl has completed the loading and display of the site. When the task is completed, it will call a method called webpage_documentcomplete (). This allows us to define the code that is executed when the web is loaded. For example, stop animation. The last line of the CREATE_A_NEW_TAB () method is enabled:

Timer1.enabled = True;

The timer easily sends the segment message to Timer1_Tick (), which changes the image displayed in the PictureBox control, as shown below:

Private void Timer1_Tick (Object Sender, Eventargs E)

{

// this method is caled by the timer, and we use it to update the

// Image displayed by the PictureBox Control to Create A Simple

// annimes.

Image_animation ;

IF (image_animation> 10) image_animation = 0;

Switch (image_animation)

{

Case 0: PictureBox_busy.image = wbe.properties.Resources.Anim0; Break;

Case 1: PictureBox_busy.image = wbe.properties.Resources.Anim1; Break;

Case 2: picturebox_busy.image = wbe.properties.Resources.Anim2; Break;

...

Case 7: picturebox_busy.image = wbe.properties.Resources.Anim7; Break;

Case 8: PictureBox_busy.image = wbe.properties.Resources.Anim8; Break;

Case 9: picturebox_busy.image = wbe.properties.Resources.Anim9; Break;

}

}

You can see that a different image is displayed in Picturebox each time the timer is excited. Use the dialog that you display when an image is assigned to the button or the PictureBox control, load the image from the disk.

The rest of the program is driven by event - call a specific method when the user clicks or enter a web address or searching a string.

For example, both the web navigation button calls the current WebBrowser control. For example, if you click the Back button, you will call the following methods:

Private void button_back_click (Object Sender, Eventargs E)

{

// Go Back - IF The Web Control Can Go Back, Do IT.

WebBrowser thiswebpage = getCurrentWebBrowser ();

IF (thiswebpage.cangoback)

THISWEBPAGE.GOBACK ();

}

When entering a URL in the Address combo box, we use the NaviGate method for the web control to get and display the page. The following code uses the text currently displayed in the combo box and passes it to the Navigate: WebBrowser THIS

转载请注明原文地址:https://www.9cbs.com/read-50005.html

New Post(0)