Databases Reference
In-Depth Information
Figure 14-16. GUI design of the AddNames form
You want the user to add a name into the TextBox and click the Add button, after
which that name will be added to the ListBox. To do so, you need to write the code
functionality behind the click event of the Add button.
7. Double-click the Add button and write the following code, which will read the
name entered into the TextBox and add it to the ListBox, inside the btnAdd_Click
event.
lstName.Items.Add(txtName.Text);
txtName.Clear();
8. Go to the Build menu and select Build Solution. You should see a message indicat-
ing a successful build.
Keep your current project open, as you'll need it immediately for the next exercise.
(Don't worry, we'll explain how this and the next exercise work afterward.)
Try It Out: Setting the Startup Form
Setting the startup form in a Visual C# project is a little tricky, so we wanted to break it
out into its own exercise. To set a startup form, you need to follow these steps:
1. In the project you modified in the previous exercise, navigate to Solution Explorer,
open the Program.cs file, and look for the following code line:
Application.Run(new WinApp());
This code line ensures the WinApp form will be the first form to run all the time; in
order to set the AddNames form as the startup form, you need to modify this
statement a little, as follows:
Application.Run(new AddNames());
Search WWH ::




Custom Search