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

If you recall, our menus invoke the menuImage_ChildClick method to alter the display mode by assigning a new SizeMode value.

INVALIDATE STATUS BAR

 

Action

Result

 

 

 

7

Modify the menuImage_Child-

protected void menuImage_ChildClick(object sender,

 

Click method to force a redraw

System.EventArgs e)

 

of the status bar.

{

 

if (sender is MenuItem)

 

 

 

 

{

 

 

MenuItem mi = (MenuItem)sender;

 

 

nSelectedImageMode = mi.Index;

 

 

pbxPhoto.SizeMode

 

 

= this.modeMenuArray[mi.Index];

 

 

pbxPhoto.Invalidate();

 

 

statusBar1.Invalidate();

 

 

}

 

 

}

 

 

 

Now the status bar will be redrawn whenever the SizeMode property is altered. Note that this change highlights another advantage of our decision in chapter 3 to handle the Click of an Image submenu item with a shared handler. If we decided to add additional display modes in the future, this code will ensure that the status bar is redrawn correctly each time it changes.

Compile and run your application to verify that the code works as expected. Display an image in both Stretch to Fit and Actual Size mode to see how the owner-drawn status bar panel behaves when the application is resized.

4.5RECAP

This chapter introduced the StatusBar class and showed how both text and panel information are displayed in this control. We looked at how to switch between the display of text and panels in a status bar, and discussed how various properties can be used to alter the appearance and behavior of status bar panels.

We also presented the base class of all Windows Forms controls by looking at the Control class in some detail. A discussion of owner-drawn panels and the use of the DrawItem and Paint events led to a discussion of the System.Drawing namespace in general, and the Graphics class in particular.

The next chapter takes us out of the Windows Forms namespace briefly in order to discuss reusable libraries.

RECAP

125

C H A P T E R

5

 

 

Reusable libraries

5.1C# classes and interfaces 127

5.2Class libraries 133

5.3Interfaces revisited 145

5.4Robustness issues 151

5.5Recap 160

This chapter is our chance to lean back in our respective chairs, take stock of where we’ve been, and plan for the future. Before we jump back into the Windows Forms classes in chapter 6, we will build some infrastructure and introduce some important programming concepts. Some of you may be familiar or comfortable with these concepts; others may not. The discussion will attempt to provide enough material to review what is needed without getting too bogged down in the minute details.

Looking at our MyPhotos application, it would be great if this application turned out to be somewhat useful. As such, it is worth laying the proper groundwork for the road ahead. So far, we have built an application with the following features:

A title bar where the name and version number of the program are displayed.

A menu bar where the user can access commands such as loading an image.

A main window that displays a single photo at a time (stretched and distorted, but displayed nonetheless).

A status bar where information about the displayed photo appears.

So now what? In this book, there are a number of features that still need to be covered. Tool bars, dialog boxes, splitters, and printing, to name a few. In order to do

126

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