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

statusBar1.ShowPanels = true;

}

else

{

// Indicate the album is empty pbxPhoto.Image = null;

statusBar1.Text = "No Photos in Album"; statusBar1.ShowPanels = false;

}

statusBar1.Invalidate();

base.OnPaint(e);

}

Our code is coming along. We can add new photos to the album, and remove the photo currently displayed.

TRY IT! Compile the code and verify that you can add and remove images to the album. Make sure you can add multiple images at once by selecting a range of images with the Shift key. This can be done by clicking the first file, holding down the Shift key, and then clicking the last file. You can also select multiple single images with the Ctrl key by clicking the first, holding down the Ctrl key, clicking the second, and so on.

Also see what happens when a nonimage file is specified. You should see our invalid image with the red X that we created in chapter 5. This indicates to the user that something is wrong, but maintains the image paradigm used by our application.

The current code does not allow us to move to the next and previous images in the album, so only the first photo in the album is ever displayed. Navigating within the album using the Next and Previous menus is our next topic.

6.4CONTEXT MENUS REVISITED

In this section we implement the Next and Previous menu items for our application. These menus are part of the View menu on the main menu bar. If you recall, this menu was cloned and assigned to the context menu for use with the PictureBox control. Our careful implementation in chapter 3 ensured that the contents of the context menu always match the contents of the View menu. In fact, your application should include these menus now, as can be seen in figure 6.2.

CONTEXT MENUS REVISITED

173

Figure 6.2

A context menu displays keyboard shortcuts just like the main menu. As a special treat, an image not yet seen in this book is shown here.

The handlers for Next and Previous use concepts we have previously discussed, so let’s get to it.

6.4.1DISPLAYING THE NEXT PHOTOGRAPH

The Next handler uses the CurrentNext method from our PhotoAlbum class, and is implemented using the following steps.

Set the version number of the MyPhotos application to 6.4.

IMPLEMENT HANDLER FOR THE NEXT MENU

 

Action

Result

 

 

 

1

Add a Click handler for

protected void menuNext_Click

 

the Next menu item.

(object sender, System.EventArgs e)

 

 

{

 

 

 

2

Implement this handler

if (_album.CurrentNext())

 

using the CurrentNext

{

 

method.

this.Invalidate();

 

}

 

 

 

 

}

 

 

 

You will note that we invalidate any image currently displayed only if a next photograph is available. It might be a good idea to beep or display a message when no next photo is available to inform the user they are at the end of the album. We will discuss how to do this in the next chapter.

6.4.2DISPLAYING THE PREVIOUS PHOTOGRAPH

The Click event for the Previous menu is implemented in a similar manner.

174

CHAPTER 6 COMMON FILE DIALOGS

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