Adding More Event Handlers to Your Controls and W
Adding More Event Handlers to Your Controls and Writing Utility Methods
This week we will add more event handlers and functions to the course project. View the videos provided in the Project Video Links for instructions and details to help guide you through your efforts. Links to other files you need are listed below.
Course Project DeVry University College of Engineering and Information Sciences
Screenshot of program running:
Form code (only the code for the form, not program.cs):
,
Course Project DeVry University College of Engineering and Information Sciences
Course Number: CEIS209
Background
Part 1: Scenario
Lucky you! Your manager has put you in charge of the lyrics videos for the monthly lip synch contest. Each contestant “sings” along with a song of their choice, prompted by the lyrics in the video. Essentially, there is a long list of songs, along with associated URLs and other information. Your manager has some basic functionality in mind, such as the ability to add and remove songs, as well as create playlists and show the videos. The application must run fast, and be updated with new features over time. Maintenance is key!
NOTE: For this project, we strongly suggest keeping a Notepad or MS Word document handy, containing the names of a few songs and associated video URLs. The URLs can be local video files on your hard drive, or videos on web-based sites such as YouTube.com.
Week 3: Adding more event handlers to your controls, and writing utility methods
Objectives
1. Create a method (a function in this case) to return true if the user entered non-empty input for the “Add Song” button, or false if not.
2. Create a method (another function) to return true if a song title is found, or false if it is not
3. Use string.Contains to determine if a song title is contained in a the text of a Listbox
4. Activate tabbing from one control to another
Introduction
So far, with your application you are able to add songs to your library. This week, the goal is to determine if a given song is in your library. At this point, your “library” is your songList ListBox. In addition, you will create two “utility methods,” which are called from your event handlers. The advantage of, for example, pulling the text box validation code out of the “Add Song” button’s event handler is that it can then be used by other methods as well. Finally, you will address that annoying need to click on each textbox in order to input song information.
Steps
1. Create the ValidInput() function. Here you will take the input validation code from your AddButton_Click event handler method and use it to make an independent method that returns true if all of the fields are non-empty and false if at least one is empty. As a side effect, it pops up a MessageBox indicating the first empty field that it finds.
Do you remember the flowchart from Week 2? As a reminder, here it is, representing the logic from the AddButton_Click event handler.
You will now simplify the AddButton_Click method by separating out the validation portion of the code, and calling the new ValidInput() function. The logic looks like this:
This is how the ValidInput function looks in C#. Again, this will be in your Form1.cs file. Only the tests for the title and the artist are shown here. You need to add the tests for genre, year, and URL. This code needs to be placed before the return isValid code.
Modify your AddButton_Click event handler so that you call the ValidInput():
2. Create the bool SongInList(string songTitle) function. This function returns true if songTitle is in the songList, and false if not. Use a similar approach to the one you used for ValidInput().
The function is passed a string containing the song title to find, and a bool flag variable is set to false (i.e., song not found yet). It then loops through the songList, (with foreach) checking for a match. If a match is found, then a bool flag variable is set to true. At the end, the value of the bool flag variable is returned.
HINT: here is some of the code you will need
3. Add a “Find Song” button. Create a new button called findButton with text “Find Song” on it. Double-click on your new findButton to bring up the code for the FindButton_Click method. FindButton_Click should use your new SongInList function to determine if the song in titleText.Text is in the songList. If the song is in the songList, use a Message Box to pop up a message saying “Song Found”. If it is not in the list, use a Message Box to show a message such as “Song not in list”.
4. Add a “Clear Song” button. Create a new button called clearSong with text “Clear” on it. Double-click on your new clearSong to bring up the code for the clearSong_Click method. This button will just clear all values entered in the text boxes.
5.
6. Test your program. Add a song title of your choice and the artist MUST by your name (screenshot). Test the validation using a blank value (screenshot) and test the find song button (screenshot).
On Your Own – Optional
Replace Genre with a ComboBox control. This control will contain a drop down list of Genre options. Feel free to choose your own list. To enter items in the list, pick the Arrow next to the combo box and click Edit Items:
Enter your own items:
Name your combobox: genreComboBox.
Everywhere in your code that you have genreText.Text, you will have to replace it with genreComboBox.SelectedItem.ToString()
You can also delete genreText.Text = “” from the Clear button.
Fix the tab index so that when you tab through your textboxes, it follows a natural progression.
Run the program and take a screenshot showing the combo box.
Deliverables Week 3
· Take a screenshot showing your Video Manager page. You should have four screenshots showing the tests you ran. Paste these in your word document deliverable page.
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.