![]() |
Tab Controls and Tab Pages |
|
Description |
|
As your application becomes crowded with various controls, you may find it running out of space. To solve such a problem, you can create many controls on a form or container and display some of them only in response to some action from the user. The alternative is to group controls in various containers and specify when the controls hosted by a particular container must be displayed. This is the idea behind the concept of property pages. |
|
A property page is a control container that appears as a form or a frame. A property page can appear by itself. Here is an example ![]() In most other cases, a property page appears in a group with other pages. It functions like a group of pieces of paper placed on top of each other. Each piece is represented by a tab that allows the user to identify it: ![]() To use a property page, the user clicks the header, also called tab, of the desired page. This brings that page up and sends the other(s) in the background: ![]() If the user needs access to another page, he or she can click the desired tab, which would bring that page in front and send the previously selected page to the back. The pages are grouped and hosted by an object called a property sheet. Like a form, the property pages of a property sheet are simply used to carry or hold other controls. The major idea of using a property sheet is its ability to have many controls available in a relatively smaller area.
Property pages of a property sheet are also referred to as tab controls. To support property pages, the .NET Framework provides a class named TabControl. At design time, to add a property sheet to your application, in the Containers section of the Toolbox, click TabControl and click the form (or another container). If you want the property sheet to occupy the whole form or to occupy a section of it, you can specify this using the Dock property. To programmatically create a property sheet, create a handle to TabControl, allocate memory for it using the gcnew operator. Like all other objects, a tab control must have a name. After declaring the variable and initializing it, add it to the Controls collection of its container. Here is an example of creating a tab control: #include <windows.h>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class CExercise : public Form
{
private:
TabControl ^ tclPropertySheet;
public:
CExercise()
{
InitializeComponent();
}
void InitializeComponent()
{
Size = System::Drawing::Size(345, 228);
tclPropertySheet = gcnew TabControl;
tclPropertySheet->Location = Point(14, 16);
tclPropertySheet->Size = System::Drawing::Size(310, 170);
Controls->Add(tclPropertySheet);
}
};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
Application::Run(gcnew CExercise());
return 0;
}
This would produce:
|
|
|
||
| Home | Copyright © 2007 FunctionX, Inc. | Next |
|
|
||