O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controls

The Control class in Windows Forms is the base class of almost all visual elements. A handful of exceptions—most notably menus and tool tips—work differently in Windows Forms because they also work differently in Win32, but the vast majority of UI elements you’ll use in a Windows Forms application will be controls.

Note

This is a significant difference between Windows Forms and WPF. WPF’s Control class (the one in System.Windows.Controls, as opposed to the Windows Forms one in System.Windows.Forms) is more specialized, as you saw in Chapter 20. In Windows Forms, not only do interactive elements such as Button derive from Control, so do layout elements. The nearest equivalent to the Windows Forms Control class in WPF and Silverlight is actually FrameworkElement.

Our application is going to have a list of entries at the top, and some fields to edit the selected entry at the bottom. We’ll use a SplitContainer to arrange these two sections—SplitContainer provides a draggable splitter bar that can be used to resize a pair of panels sharing some space on-screen. We add this by dragging it from the Toolbox’s Containers section onto the form. It automatically fills the whole window. However, it splits the window with a vertical splitter—the two halves are on the left and right, but we wanted them on the top and bottom. This is easily fixed, because like many controls, the SplitContainer offers a pop-up window for performing common tasks. At the top-righthand corner of the control, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required