CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++

Third Intermediate Windows Forms Example

The Changes

Take your previous Windows Forms App, made with the directions for C#, and modify it as follows. We add a class function (a method) for finding the area and call this function from the click handler.

private void CalculateButton_Click(object sender, EventArgs e)
   float Area, Length, Width;

      Length = Convert.ToSingle(LengthTextBox.Text);
      Width = Convert.ToSingle(WidthTextBox.Text);
      if ((Length > 0) && (Width > 0))
         Area = CalcArea(Length, Width);
         AreaTextBox.Text = Convert.ToString(Area);
         AreaTextBox.Text = "Area undefined";
   catch (Exception ex)
      AreaTextBox.Text = "Exception " + ex;

// Calculate area of a rectangle
private float CalcArea(float Len, float Wid)
   return Len * Wid;

Try It Out

Save all of your files. Build your project and then start it without debugging.

Class View

This is an appropriate place to take a look at Class View. It often appears on a tab next to Solution Explorer. If not, look for it under the View menu. After you click on this tab, it should show you the name of your project. If you click on the small triangle in front of this, it will expand to show you the namespace that contains your code. Right click on this namespace and select View Class Diagram. In the resulting class diagram you can click on the downward arrowlike symbol in the upper right corner of the Form1 class to see what is inside this class. What you see will be the fields and methods of the class. Some of those methods are ones that you created. Finally, at the bottom of the window you will see a Class Details section showing more information about the fields, properties, methods, and events for this class. You can even add the outline for a new method in this deails section.

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: November 21, 2014