How to Add Functionality to the Application in MS Visual Studio 2005
Video Transcript
Okay, our user interface looks great but it does not really do anything. The next thing we will need to do is start writing some code.
First, we will add some functionality to our back and forward buttons. Double click on the back button. This will bring you to the click event. Let us add some functionality to have our web browser navigate backwards.
Hit control space to bring up intellisense and start by typing in the web browser control name WEB. You will see a web browser one popup. Select that option and press Tab. Next, select the period. This gives you a list of methods of your web browser control. You can see there is quite a view, not only including going back and going forward but also navigating home and navigating to search.
I will leave it up to you to add this functionality. For now, we will go ahead and select the go back method so that we have some logic behind our button. We want to do the same thing for our go forward button.
Go to the form design, double click on the forward button and we will add the same logic here. Use intellisense to help you along. Select web browser one and select go forward. I now have navigation functionality for my browser.
The next thing I want to do is go ahead and capture the address that the user types in. The default as you know is Microsoft.com. However, the user may have other ideas in where they would like to go. Double click on the red arrow and we will go ahead and add some code here as well. Use intellisense to navigate into your web browser control, select the URL property, and this time, we are going to take the URL property from the address text bar and pass it in to this property. Type in new system, URI, open parenthesis, and now use intellisense to navigate to your address URL. It will be listed tool strip and scroll down using your arrow keys and select the tool strip text box 1. Hit the Tab button to accept this and we will also want a text property for this control. Close your parenthesis and you are done your line of code. Now, the user information will be passed to the browser. Let us go back to the design.
Now, we will go ahead and want to program three events of our browser. The Document Completed Event, the Navigating Event and the Progress Chained Event. We will use these events to change our status bar to show progress to the user.
Double click on the web browser. This brings you to your Document Completed Event. We will write a few lines of code here to indicate the status. Use intellisense and select status label, select the text property, and instead of showing the default ready, we will go ahead and show done. We will go ahead and make the progress bar visible. Use intellisense and select the status progress. Use intellisense and start the visible property and set this equal to false.
Next, we will go ahead and add some code to the Navigating Event. Click below the event you just added, add a few lines and go to the top of the editor. Scroll down until you see the web browser control. If you look on the right drop down list, you will see a list of events that are available. I want to go ahead and program against the Navigating Event. So go ahead and select that event from your drop down list. The Navigating Event occurs on my web browser is navigating to a site. In this case, I want to go ahead and show the progress bar so that the user can see the current progress. Use intellisense and set the visible property of your progress bar. You set status progress.visible=true.
And lastly, we will have to add the most code to the Progress Chained Event. Go ahead and select the web browser control from the left hand drop down and go ahead and choose in this case the Progress Chained Event. Inside this event, I am going to have to indicate to my progress bar what the progress of the browser is. I can use a parameter called E which provides the event arguments for this event. Let us go ahead and write some code.
The first thing I need to do is check to see if the current progress equals -1. If the current progress equals -1, it means that the document has fin
Okay, our user interface looks great but it does not really do anything. The next thing we will need to do is start writing some code.
First, we will add some functionality to our back and forward buttons. Double click on the back button. This will bring you to the click...
click to read more