Windows Forms Applications: Creating a simple app

Nicoleta Ciauşu
2 min readNov 18, 2016

--

In today’s C# lesson we’re going to learn a bit about the most basic things about programming using Windows Forms by creating a simple application which is going to take information from a few textboxes, checkboxes and radio buttons and add them into a listBox. Then, using a few buttons, we will add functionality to our app: adding an entry to the list, clearing the list, and removing the last element from the list.

Here is what the design of the application looks like:

Not exactly amazing, but this is not a design course.

The placement of the elements is pretty straight-forward. One interesting thing to note are the groupBoxes, which ..group the elements so you won’t have issues with having two radio buttons checked at the same time, for example. I find it really nifty that VS takes care of that for you.

As for the code..

This is the code used for adding an item to the list. What this does, basically, is combining the strings taken from the textBoxes with the selected gender and whatever other traits the person picked and concatenating them into a big string which is then added into the listBox.

This nifty code snipplet simply calls the method listBox1.Items.Clear(), which clears the entire listBox.

Finally, using a try-catch to avoid trying to remove an element when there are no items in the listBox, we call the method listBox1.Items.RemoveAt(int index) to remove the last element.

That is all for today. In a future post, I will add some more functionality to the program.

--

--

Nicoleta Ciauşu

Programming enthusiast, sharing my software development journey & insights. Comp Sci grad, MSc student :)