Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
It doesn't matter how good the UI designer tools are inside Visual Studio. They can't do everything for you. At some point, we must write some code. I'm going to write some code in this project called InfoReaderV3, and I'm going to double-click on this MainWindow.xaml file. So let's take a minute to look around our UI. I have a number of elements in here from the previous movie, and I'm going to work with these two buttons here: this Search Bing button and this Get RSS button. So the idea is you're going to type some text in the Search Term textbox, and this textbook has a name; it's called searchText.
Names are important because in order to talk to them in your code, they have to have an identifying name. The user's going to type something in this text box. They'll click on the Search Bing button. Now, as you can see, this button does not have a name, so I need to provide it a name. And then I'll take the results from the Bing web site, and I'll put it done here in this control, which is named browser; it's a web browser control. So before I continue, I would like to name both these buttons. I will click on the Search Bing button and then go over to the Properties window and type in a new name up here at the top.
I'm going to call this one searchAsRSSButton. Now, by naming this, I'll also get more readable event procedure names when I'm ready to write my code. So, now I'm going to go to this button. I'll show you several ways to add code to your project. I'm going to double-click on the Search Bing button, and Visual Studio will switch me over to the Code window, and it automatically stubs in a function with the name of my button and then _Click. The other way to stub in code--I'll switch back, I just did a Ctrl+Tab to switch back to the other item-- I'll click on this RSS button, and instead of double-clicking here, I can go over to the Properties window and click the Events tab, and then I can find the event I want--in this case the Click event--and double-click here, or I can type my own name in, if I'd rather.
I think I'll just double-click on this one to stub the code in here too. Now I have these two buttons. I'm going to write one more procedure, my own custom procedure, which I'm going to call from both these buttons. It's going to be a private function. It's going to return a void value. It's going to be called SendToBing(). I need the two parentheses to signify that it's a method. Then I move down to the next line, and I type the two curly braces, which signify the section where I write my code inside the function. I'm going to pass in a parameter from both of these functions.
The idea is if you click on the searchBingButton, then I'm going to pass in a false, because I don't want the data returned as an RSS feed. So I'm going to create a parameter down here called searchAsRSS, and then up here, I will call that function. The nice thing about the IntelliSense Engine in Visual Studio is that it knows that I've just written that function, and it shows me in my IntelliSense list. I'm going to click the down arrow on my keyboard and then press the Tab key to have it finish typing, then an open parenthesis, the word "false", and then to end the line of code in C# you use a semicolon.
I'm now going to copy this, right-click and choose Copy, and then I'm going to come down here and do a Ctrl+V to paste, and then I need to change this to true. Let's review what I did. I wrote two procedures using the Visual Studio "auto stubbing in of the code" future. That's not the official name, but I just double-clicked on the button, and it stubbed in the code. Then I wrote my own custom function down here, SendToBing, and then I'm calling that custom function when I click on the two buttons. Now, you have the basic infrastructure written. In the next movie, I'll show you how to test this code and also how to retrieve information from the Bing search engine.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 103120 Viewers
61 Video lessons · 89778 Viewers
71 Video lessons · 73407 Viewers
56 Video lessons · 104960 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.