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

ADD A MENU AND LIST VIEW TO OUR FORM (continued)

 

 

 

Action

 

 

Result

 

 

 

 

 

 

6

Place a ListView control onto the

 

 

form.

 

 

 

 

 

 

How-to

 

 

 

 

 

 

Use the tool box as you would for any

 

 

other control.

 

 

 

 

 

 

 

Settings

 

 

 

 

 

 

 

 

 

Property

 

Value

 

 

 

(Name)

 

listViewMain

 

 

 

Dock

 

 

Fill

 

 

 

 

 

 

 

 

 

Since we already know how to manipulate menu objects, we may as well set up the appropriate event handlers here as well. We will need a Popup event handler for the View menu to make sure the appropriate menu item is checked, and a Click menu for each item to assign the ListView.View property to the corresponding value. We could try to do something fancy here to limit the amount of code we needed to write. Instead, we will simply code this up directly and save our fancy tricks for later.

ADD EVENT HANDLERS FOR THE VIEW MENU

 

Action

Result

 

 

 

7

Add a Popup event handler

private void menuView_Popup

 

for the View menu.

(object sender, System.EventArgs e)

 

 

{

 

 

 

8

Implement this handler to

View v = listViewMain.View;

 

check the appropriate entry

menuLargeIcons.Checked = (v == View.LargeIcon);

 

based on the View property

menuSmallIcons.Checked = (v == View.SmallIcon);

 

menuList.Checked = (v == View.List);

 

of the ListView control.

 

menuDetails.Checked = (v == View.Details);

 

 

}

 

 

 

THE LISTVIEW CLASS

447

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