Tuesday, May 17, 2016

Program 10: Windows Application: Creating a Web Browser

  1.   1. Open Visual studio 2013. 
  2.      On the menu bar, choose File, New, and Project. Choose Programming language as Visual C#
  3.      In the templates list, choose the Windows Forms Application icon.
  4.      Name the project as Web Browser and specify the address of your folder.
  5.      In the main window design the form as shown below and set the properties as required.
  6.      This form uses a text box for URL, one webbrowser control and few buttons. Name these controls as required. The buttons are placed on the address bar. One button for go, one for Home, One for forward and another for backward.


Web Browser form


1.      7.  In btnGo_Click() method write the following code

private void btnGo_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(txtURL.Text);
        }
2.      8. In btnHome_Click () method write the following code

        private void btnHome_Click(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
        }
3.     9.  In btnForward_Click () method write the following code

        private void btnForward_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }
4.     10.  In btnBack_Click() method write the following code

        private void btnBack_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

5.      11.  In WebBrowser_Load () method write the following code
        
       private void WebBrowser_Load(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
        }

6.     12.  In WebBrowser_Resize () method write the following code

        private void WebBrowser_Resize(object sender, EventArgs e)
        {
            webBrowser1.Left = 10;
            webBrowser1.Top = 50;
            webBrowser1.Width = this.Width - 40;
            webBrowser1.Height = this.Height - 100;
            txtURL.Left = 120;
            txtURL.Top = 10;
            txtURL.Width = this.Width - 180;
            btnGo.Left = this.Width - 60;
        }
13.      Run the program and Check the results.

Enjoy Programming..

No comments:

Post a Comment