VB Net -Browser - Free Web Addresses

advertisement
Visual Basic First App- Web Browser
Your first step in creating a Visual Basic program is to open Visual Studio and create a
project. You will do this when creating any Visual Basic program
To create a project for your program
1.
From the Windows Start menu, choose Microsoft Visual Basic 2005 Express Edition.
The "Welcome to Visual Basic Express"
screen appears. This is the interface for
Visual Basic 2005 Express Edition,
also known as the integrated
development environment or IDE.
2.
On the File menu, click New Project.
The New Project dialog box opens.
3.
Select Windows Application and click OK.
click OK
FirstApp-WebBrowser
WED
1
A new form displays in the IDE, and the necessary files for your project are added to the
Solution Explorer window. If this is the first Windows Application project that
you have created, it is named "WindowsApplication1".
It is now time to start building your Web browser. You will use Microsoft Visual Basic 2005
Express Edition to build the user interface (the visible part that users interact with) by adding
controls from the Toolbox to the form.
The Toolbox is on the left side of Visual Studio and consists of several tabs such as Data,
Components, and All Windows Forms. Inside each tab is a set of entries that represent
controls or components that you can add to your application. For example, the All Windows
Forms tab has entries named TextBox, Button, and CheckBox that represent controls that
you can add to your application by dragging them onto the form.
FirstApp-WebBrowser
WED
2
To add controls to your application
1. Click the Toolbox panel.
The Toolbox opens.
2. Click the All Windows Forms tab of the Toolbox, select the Panel control, and then drag
a panel onto the top-left corner of the form.
3. From the same tab, drag a Button control and place it on top of the Panel.
FirstApp-WebBrowser
WED
3
4. From the same tab, drag a TextBox control and place it on top of the Panel.
5. Finally, from the All Windows Forms tab, select a WebBrowser control and place it
below the Panel.
FirstApp-WebBrowser
WED
4
To set the properties of your controls
You have now created a user interface by adding controls to your application. At this point,
however, it neither looks like nor functions as a finished application. You need to set
properties to control the appearance of your controls, using the Properties window.
1. In the Form Designer, select the Panel control.
a. The Properties window in the lower-right corner of the IDE displays all properties for
the Panel control named Panel1.
b. In the Properties window, select the Dock property, and then click the arrow to the
right. A small property-selection window with several boxes is displayed.
c. Click the top box in the property-selection window to set the Dock property to Top.
The Panel control expands to fill the top of the form.
2. In the Form Designer, select the WebBrowser control. In the Properties window, set its
Dock property to Fill by selecting the Dock property, clicking the arrow to the right, and
selecting the centre box in the property-selection window.
FirstApp-WebBrowser
WED
5
3. In the Form Designer, select the Button control.
In the Properties window, select the Text property of the Button control.
This is the text written on the button; change it from Button1 to Go!.
4. Resize or relocate any of the controls, and resize the form to suit your taste.
Panel
-Docked to top
button
Text box
Web Browser
-Docked to Centre
FirstApp-WebBrowser
WED
6
To add code and functionality to your program
Your user interface is now complete! All you have to do is add the instructions (also called
code) for how you want your program to work. In the next lesson, you will add a line of code
to your program.
1. In the Form Designer, double-click the Button control (the GO! Button).
A new window called the Code Editor opens. This is where you add all the code for
your program.
2. In the Code Editor, type the following line:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, .. .. ..
WebBrowser1.Navigate(TextBox1.Text)
End Sub
End Class
This code will run when users click the button.
To run your program
Now that your program is complete, it is time to run and test it. For complex programs, testing
can be a long and difficult process, which will be discussed in detail in a later lesson. Happily,
for this program, all you need to do is run it!
1. Connect your computer to the Internet.
2. To run your program:
Press the green start button
or Press
F5
FirstApp-WebBrowser
WED
7
2. In the text box, type http://www.microsoft.com and click the Go! button.
The WebBrowser control in your program navigates to the Microsoft home page. From
there, you can navigate through any related links. To visit another Web page, type the
address in the text box and click the Go! Button.
Try: http://www.eee.hiflyers.co.uk
3. To close the program, on the Debug menu, click Stop Debugging.
You can also end the program by clicking the Close button on the top-right corner of
the form.
Congratulations! Your first Visual Basic program is complete. You have demonstrated how
powerful programs can be developed quickly and easily by using Visual Basic. In the
following lessons, you will be introduced to more features of the Visual Basic programming
language.
FirstApp-WebBrowser
WED
8
Download