Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# ПІДРУЧНИКИ / c# / Manning - Windows.forms.programming.with.c#.pdf
Скачиваний:
108
Добавлен:
12.02.2016
Размер:
14.98 Mб
Скачать

The radio buttons receive focus when you type the access key Alt+O to activate the GroupBox control.

Modifying the display option for the album alters the Photograph setting displayed in the status bar of the main form.

The password entry controls are enabled and disabled automatically as the CheckBox control is clicked. Note how the txtPassword control receives focus automatically when the controls are enabled.

Try to enter a blank password or an invalid confirmation password to see how the validation behaves for these controls.

Feel free to experiment with some of the settings here. Also make sure the album and photograph settings are saved and restored properly whenever you close and later open an album.

TRY IT! Use the Appearance property to modify the radio buttons in the AlbumEditDlg form to be toggle buttons rather than normal radio buttons. Compile and run the program to see the toggle button behavior in action. Users typically expect normal radio buttons for situations like this, so make sure you have a good reason for using an alternate appearance when you choose to do so.

9.4RECAP

In this chapter we reviewed the basic controls in Windows Forms, namely the Label, TextBox, Button, RadioButton, and CheckBox controls. The majority of applications include one or more of these controls, and many dialogs are based exclusively on these classes. We examined the members, focus behavior, and some special features of each control, and used each control in our dialogs.

We also examined how one Form can be based on another Form using form inheritance. We constructed a base form and used it while building our two dialogs in Visual Studio .NET. During this process we also took a look at the container controls Panel and GroupBox as a way to logically arrange controls on a form, and in particular to define a distinct group for a set of radio buttons.

Along the way we looked at access modifiers for controls on a form, the DateTime structure, the C# delegate keyword, keyboard events, the Tag property, and focus events. You can review these topics by looking back through the chapter or by locating the appropriate page number using the book’s index.

There are a number of other controls in .NET, of course. The next chapter continues our discussion on controls in Windows Forms with a detailed discussion of the

ListBox and ComboBox controls.

RECAP

313

C H A P T E R

1 0

 

 

List controls

10.1

List boxes 315

10.4

Combo box edits

339

10.2

Multiselection list boxes 325

10.5

Owner-drawn lists

343

10.3

Combo boxes 333

10.6

Recap 352

 

This chapter continues our discussion of the Windows Forms controls available in the

.NET Framework. The controls we saw in chapter 9 each presented a single item, such as a string of text or a button with associated text. In this chapter we will look at some controls useful for presenting collections of items in Windows-based applications.

While it is certainly possible to use a multiline Textbox control to present a scrollable list of items, this control does not allow the user to select and manipulate individual items. This is where the ListBox and other list controls come in. These controls present a scrollable list of objects that can be individually selected, highlighted, moved, and otherwise manipulated by your program. In this chapter we will look at the ListBox and ComboBox controls in some detail. We will discuss the following topics:

Presenting a collection of objects using the ListBox class.

Supporting single and multiple selections in a list box.

Drawing custom list items in a list box.

Displaying a selection using the ComboBox class.

Dynamically interacting with the items in a combo box.

314

Соседние файлы в папке c#