Lab 6 - Visual C++ GUI – Part 2
In Lab 5, you learned how to create a windows form application from scratch. In this lab, you will learn how to use MSDN for your future development.
- Create a NewProject in Visual Studio 2017.
- In the Project Types pane, select “Online” and choose “Templates->Visual C++”, you should see a “Windows Forms” template called “C++/CLR Windows Forms für Visual Studio 2017”. Select it to create your project. You will need to install the template for the first time use. (If you are on a lab computer and cannot install the template or not comfortable with a German project template, simple follow Lab5 steps to create your project.)
- Rename the projectLab6and save on yourJ: drive. Then add a windows form and make the following:
- The functionality should be obvious: clicking the “Add String” Button adds what’s in the TextBox into the ListBox, unless the TextBox is empty. Clicking the “Delete Selected Text” deletes the selected string from the ListBox, but does nothing if nothing is selected in the ListBox.
The list must be sorted (Hint: this is a property of ListBox).
- See next page for help on these classes: TextBox and ListBox.
A couple of hints:
- Look at the Items and SelectedIndex Properties of ListBox. Find information on the Add and RemoveAt methods of Items.
- The Text Property of TextBox returns a .NET String. These strings are similar to Java strings. For example, they have a Length property. This is a lot nicer than C strings!
Build, Link, Run, Test. Make sure that you don’t add in the string if the TextBox is empty and you check if something is selected before trying to delete it.
This lab can be done in about 4 – 6 lines of code, depending on whether or not you make temporary variables.After you are done, rename your .exe file as Lab6_username.exe and submit it to S:\Courses\CSSE\shiy\2630\1Dropbox folder.
- We are going to use online help from Microsoft in lieu of using MS Studio 2017.
- For help on the TextBox class go to Look for Text under Properties.
- For help on the ListBox class go to
- Look for “Items” under “Properties”. Click on Items. Scroll down and look at the C# example to figure out how Text is added to the ListBox object.
- In a similar fashion, find “SelectedIndex” as a property of ListBox.
- Note that there are Add and RemoveAt methods for Items.
- Generally, there is NO information OR examples on C++. There usually are examples in C#. So one can look at the C# examples and use the next hint.