![]() |
The Form's Measures |
|
The Form's Size |
|
A form's size is the amount of space it is occupying on the screen. It is expressed as its width and its height. The width of a form is the distance from its left to its right borders. The height is the distance from the top to the bottom borders of a form: ![]() |
|
When you create a form, it assumes a default size. To set or change the size of a form, at design time, first click it to select it. Then, position the mouse on its right, bottom, or bottom-right handles. This changes the mouse cursor in one of three shapes: ![]()
|
|
With the mouse positioned, drag in the desired direction. If you don't want to be able to resize a form and you want to prevent this by accident, at design time, set the form's Locked property to True. If you do this:
![]()
Besides resizing the form by dragging one of its handles, to change the size of a form, select it and, in the Properties window, click the + button of the Size field. Then type the desired value for the Width and the desired value for the Height. The values must be natural numbers. To programmatically change the size of a form, assign the desired values to either or both its Width and Height properties. Here is an example: public ref class CExercise : public Form
{
public:
CExercise()
{
InitializeComponent();
}
void InitializeComponent()
{
Text = L"Windows Fundmentals - Programming";
Icon = gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
ControlBox = true;
MinimizeBox = true;
MaximizeBox = false;
Width = 425;
Height = 308;
}
};
Alternatively, you can assign a Size value to the Size property of the form. Here is an example: public ref class CExercise : public Form
{
public:
CExercise()
{
InitializeComponent();
}
void InitializeComponent()
{
Text = L"Windows Fundmentals - Programming";
Icon = gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
StartPosition = FormStartPosition::WindowsDefaultLocation;
ControlBox = true;
MinimizeBox = true;
MaximizeBox = false;
Size = System::Drawing::Size(425, 308);
}
};
If you want the operating system to specify the size of the form, set its StartPosition property to WindowsDefaultBounds. In this case, a value called CW_USEDEFAULT would be assigned to both the Width and the Height properties.
A form can be made to look like a regular rectangular host made of a system icon and the system buttons. Depending on your goals, you can also make a form appear as a dialog box or a dockable window. The borders of a form are controlled by the FormBorderStyle property. If you set both the MinimizeBox and the MaximizeBox properties to False, we saw that the form would have only the system Close button, but the form can still be resized. If you want the form to display only the system Close button and to prevent the user from resizing it, set its FormBorderStyle property to FixedDialog. Here is an example: public ref class CExercise : public Form
{
public:
CExercise()
{
InitializeComponent();
}
void InitializeComponent()
{
Text = L"Windows Fundmentals - Programming";
Icon = gcnew System::Drawing::Icon(L"C:\\Programs\\RedBook.ico");
StartPosition = FormStartPosition::WindowsDefaultLocation;
ControlBox = true;
MinimizeBox = true;
MaximizeBox = false;
Size = System::Drawing::Size(425, 308);
FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
}
};
|
|
|
||
| Previous | Copyright © 2007 FunctionX, Inc. | Next |
|
|
||