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

2.4.1Assign the Anchor property

In chapter 1 we set the Anchor property for our Button control to Top and Left, and for our PictureBox control to Top, Bottom, Left, and Right. In Visual Studio .NET, the default value of Top and Left is already set for our button, so we only need to modify the property for the pbxPhoto control. The result of this change when running the application is shown in figure 2.6.

Set the version number of the application to 2.4.

SET THE ANCHOR PROPERTY FOR THE PBXPHOTO CONTROL

 

Action

Result

 

 

 

1

Display the properties for

 

 

the PictureBox control.

 

 

 

 

2

Use the Anchor property to

 

 

anchor this control to all

 

 

four sides of the form.

 

 

How-to

 

 

a. Click the down arrow for

 

 

the Anchor item setting.

 

 

b. Click the corresponding

 

 

value to select Top, Bot-

 

 

tom, Left, and Right.

 

 

c. Click outside the drop-

 

 

down dialog to set the

 

 

selected values.

 

 

 

 

Visual Studio recognizes that the Anchor property is an enumeration containing a set of or’d values, so it breaks apart the value into its components.4 For the PictureBox control, this displays the value as “Top, Bottom, Left, Right.” If you look in the InitializeComponent method generated by Visual Studio, you will notice that this value is set much like our code in chapter 1. Note that the Button.Anchor property is not set in this method since it uses the default value.

this.pbxPhoto.Anchor = (((System.Windows.Forms.AnchorStyles.Top

| System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right);

4 This occurs because the AnchorStyles enumeration has the FlagsAttribute attribute assigned. An attribute is a C# construct that defines a behavior or configuration setting for a type, in this case the fact that the enumeration allows a bitwise combination of its member values.

RESIZING FORMS

63

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