Chapter 16. Rounding Out Our Application, Part 2: Adding a Graphical User Interface

In Chapter 15, we greatly improved the usefulness of the Student Registration System (SRS) application by providing a means for persisting the state of Student objects—in particular, their enrollment status in various classes—from one SRS invocation to the next. However, we still haven't provided a means by which a student user can interact with the SRS. As it is currently implemented, we launch the application from the command line by running the SRS executable, and from then on the application runs to completion without any further user input, relying solely on ASCII files and/or hard-coded information as its "fuel" (data).

In this chapter, we'll enhance our latest version of the SRS application once again by retrofitting a graphical user interface (GUI) front-end. With the GUI that we add, we'll provide hypothetical student users with the capability to do the following:

  • Log on to the SRS.

  • View the schedule of sections available for registration in the current semester.

  • View and modify their individual course load by dropping and adding sections of courses that they are eligible to attend.

  • Save these changes to a file before logging off again.

In this chapter, you'll learn the following:

  • The basics of C# GUI composition and event handling

  • What the GUI classes in the System.Windows.Forms and System.Drawing namespaces have to offer

  • Details about a number of Framework Class Library (FCL) GUI classes

  • A recommended architecture for C# GUI applications

  • The importance of developing an overall plan for how the GUI is to look, operate, and "flow," called a concept of operations, before any code is written

  • How to retrofit a GUI to an existing application, using our SRS application from Chapter 15 as an example

When reading this chapter, note that it's meant to provide only an introduction to C# GUI development. Our goal is to teach you how to create a simple, yet completely functional GUI front-end for our SRS application. With this goal in mind, we'll cover only the subset of available GUI classes that we'll need for building the SRS GUI. Furthermore, we'll cover only those features of these classes that we'll be taking advantage of when building our GUI. Nonetheless, you'll gain valuable insights into the fundamentals of C# GUI building and event handling.

When you develop your own GUIs for job or school assignments, you will very likely use an integrated development environment (IDE) such as Visual Studio that will write a lot of the GUI code for you. In this chapter, however, we'll go through the process of writing a GUI front-end for an application from scratch. Although IDEs can improve productivity, it's our opinion that when an IDE does some of the work for you, there is a tendency to not pay as much attention to what is going on. You don't learn as much. On the other hand, when you write the GUI code (or any code), you (and only you) are responsible for getting the code to work. You'll really learn the ins and outs of how a program works and how to debug it when it doesn't.

With those caveats out of the way, let's dive into the world of C# GUIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset