Lab Creating a Web Browser

In this lab, you will create a limited but functional Web browser. You will add controls to facilitate backward and forward navigation, as well as allowing a user to type a URL and navigate to the specified location.

► Exercise 1: Creating a Web Browser

1. In Visual Studio, start a new Windows Forms project.

2. In the Properties window for Forml, set the Size property to 600,400.

3. From the Toolbox, drag a SplitContainer onto the Form.

4. From the Toolbox, drag a WebBrowser control onto Panel2.

5. From the Toolbox, drag three Button controls and a TextBox control onto Panell.

6. Set the Text property of the Button controls to &Back, &Forward, and &Navigate.

7. Set the UseMnemonic property of each Button control to True.

8. Select the SplitContainer. In the Properties window, set the Orientation property to Horizontal and adjust the size of Panel1 so that just the buttons are showing. Set the FixedPanel property to Panel1.

9. In the Designer, double-click the Back button to open the Button_Click event handler for this button. Add the following line of code:

webBrowser1.GoBack();

10. In the Designer, double-click the Forward button to open the Button_Click event handler for this button. Add the following line of code:

WebBrowser1.GoForward() // C#

webBrowser1.GoForward();

11. In the Designer, double-click the Navigate button to open the Button_Click event handler for this button. Add the following line of code:

WebBrowser1.Navi gate(TextBox1.Text) // C#

webBrowser1.Navigate(textBox1.Text);

12. Press F5 to build and test your application.

Was this article helpful?

0 0

Post a comment