Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Manning - Windows Forms Programming With CSharp.pdf
Скачиваний:
72
Добавлен:
24.05.2014
Размер:
14.98 Mб
Скачать

2.4.2Assign the MinimumSize property

To match our application from chapter 1, we also need to set the MinimumSize property to ensure that the window will never be so small that the PictureBox disappears. This is done with the following steps:

SET THE MINIMUMSIZE PROPERTY FOR THE PBXPHOTO CONTROL

Action

Result

1Display the properties for the Form object.

2

Set the value of the

The code in InitializeComponent sets this new value.

 

MinimumSize

this.MinimumSize = new System.Drawing.Size(200, 200);

 

property to “200, 200”

 

 

Compile and run the application to verify that the program resizes similar to figure 2.6. Once again note that the aspect ratio is not preserved by our application. This is a known bug that we will fix later in the book.

Now that we have duplicated the MyForm program from chapter 1, you might take a look at the source code in MainForm.cs and compare it to our final MyForm.cs listing. Other than some of the differences we pointed out at the start of this chapter, you will see that the code is much the same.

TRY IT! First, change the Anchor setting for the PictureBox control to use Dock instead. In the Properties window, you will notice a dropdown for this property similar to the one shown for the Anchor property, as in figure 2.7. Here you select the section of the box to dock against, namely the Top,

Left, Right, Bottom, Fill (in the middle), or

None. In figure 2.7, the DockStyle.Fill value

is selected. If the picture box covers up the Load

Figure 2.7 The Dock

property dropdown

 

button, right-click the picture box and select the window.

“Send to Back” option to send the control to the

 

end of the z-order. Compile and run the program to see the new behavior. Second, for the adventurous, try adding a second Button and PictureBox control to the application using Visual Studio .NET, similar to the task suggested at the end of chapter 1. Name the button btnLoad2 and set the text on the label to “Loa&d2” with a Click event handler that loads a second image and displays it in the second PictureBox named pbxPhoto2. You can use the anchor property for these, or set the Dock property for the first picture box to DockStyle.Top, and for the second

picture box to DockStyle.Fill.

64

CHAPTER 2 GETTING STARTED WITH VISUAL STUDIO .NET