Moreover microsoft has indicated that windows forms

Info icon This preview shows pages 820–822. Sign up to view the full content.

View Full Document Right Arrow Icon
designed with Xaml in mind.) Moreover, Microsoft has indicated that Windows Forms is unlikely to see much significant new development—it will be fully supported for years to come, but it will not grow many new features. Since you’ve continued reading, presumably the benefits are of interest to you, so in this chapter, we’ll walk through the creation of a simple Windows Forms application to show you the Visual Studio designer support and the main aspects of the program- ming model. Creating the Application We’ll build a simple application for showing and editing a to-do list. To create a new Windows Forms application, open the New Project dialog (Ctrl-Shift-N) and in the Installed Templates on the left, select Visual C# Windows. In the templates in the middle, select Windows Forms Application. We’ll call our project ToDoList . Visual Studio will create a new project with a single form called Form1 —a class derived from the Form base class. A Form is just a window—the name reflects the fact that one of the tasks Windows Forms is particularly well suited to is making line-of-business applica- tions that involve filling in forms. Visual Studio will be showing the empty form in a design view that you can drag controls onto. However, before we start adding the UI, we’re going to define a class to represent the to-do items in our application. So we’ll add a new class called ToDoEntry to the project, shown in Example 22-1 . 796 | Chapter 22: Windows Forms
Image of page 820

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Example 22-1. Class representing to-do list entries public class ToDoEntry { public string Title { get; set; } public string Description { get; set; } public DateTime DueDate { get; set; } } If you’re following this in Visual Studio, make sure you build your project after adding this class. We’re going to be using some design-time features of Visual Studio that will need to know about your class, and you need to have built the project for these to work. Next, we need to make sure Windows Forms knows we’re using this class as a data source, which we’ll do by creating a binding source . Adding a Binding Source The BindingSource class keeps track of how a Windows Forms UI is using a particular data source. When you have a collection of items, such as the entries in our to-do list, the BindingSource tracks which item is currently selected and can coordinate additions, deletions, and changes. Using a BindingSource can also make life easier in the UI de- signer, because it provides Visual Studio with information about the data you’re work- ing with so that it can help connect that data to your controls. We add a BindingSource by going back to the design view of Form1 , making sure Visual Studio’s Toolbox is open (which you can do from the View menu if it’s not already visible), and then expanding the Data section of the Toolbox. This section contains a BindingSource item, which we drag onto the form.
Image of page 821
Image of page 822
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern