VCL Controls: The Bevel

 

Introduction

A bevel is a VCL control used to enhance the display of a form by adding a box, a frame or a line. A bevel shares a lot of the other controlsí properties, this means that you can modify them at design and/or run times.

To add a bevel object to your form, click the Bevel button on the Additional tab of the Component Palette and click on the form.

Bevel Properties

In its uniqueness, although the bevel does not have much functionality, some of its properties make it a valuable accessory for your formís look. By default, a bevel does not have a particular alignment on the form; it completely depends on the developer. Unlike the TForm and TPanel controls, the bevel control is not a container; therefore, although you can place controls inside a bevel, the bevel does not control their position or alignment. In other words, the bevel does not ďownĒ them.

The two most important properties of a bevel are its shape and its style. The Shape property is a TBevelShape enumerator that controls how the bevel appears. You can set the bevel to appear as a line, to show borders or to be empty. To set the shape of the bevel, click it on the form to select it. On the Object Inspector, click Shape to reveal its combo box and select from the list. To set the bevelís shape programmatically, use code such as this:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Bevel1->Shape = bsFrame;
}
//---------------------------------------------------------------------------

The Style property is a TBevelStyle enumerator that specifies whether the bevel will be lowered or raised with regard to the surface of its host container.

Bevel Methods

The Bevel control has no other methods than the constructor and the destructor. All of its methods are derived from its parent and ancestor classes.

If you want to dynamically create a bevel, declare a TBevel object. Using the new operator, assign it the bevel constructor specifying the control component as the form on which the bevel will be positioned. You must also specify the control parent of the bevel. You can dynamically create a bevel inside of a function or another controlís event. In the following example, a bevel is created in an OnClick event of a button:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TBevel* Bvl = new TBevel(Form1);
    Bvl->Parent = this;
}
//---------------------------------------------------------------------------

If you create a bevel in a function, the control would not be available to other sections of a program. If you want the control to be global, declare a TBevel object in the unitís header file in the private or the public sections:

private: // User declarations
    TBevel *Beauty;

In the formís constructor, initialize the control using the new operator and specifying the component that would host the control:

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
 : TForm(Owner)
{
    Beauty = new TBevel(Form1);
}
//---------------------------------------------------------------------------

After creating the control, you can programmatically set its properties. If the control was created locally, set these properties in the function or event:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TBevel* Bvl = new TBevel(Form1);
    Bvl->Parent = this;
    Bvl->Height = 115;
    Bvl->Left = 8;
    Bvl->Shape = bsFrame;
    Bvl->Style = bsRaised;
    Bvl->Top = 8;
    Bvl->Width = 210;
}
//---------------------------------------------------------------------------

If you had created the control in the header file, you can use a function or event to initialize the control:

//---------------------------------------------------------------------------
void __fastcall TForm1::ControlTheBevel()
{
    Beauty->Parent = Form1;
    Beauty->Left = 240;
    Beauty->Width = 146;
    Beauty->Top = 80;
    Beauty->Height = 100;
    Beauty->Style = bsRaised;
}
//---------------------------------------------------------------------------

To manipulate the control, you can use any event of the form. For example, the following code sets the bevelís anchors:

//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
    Beauty->Anchors = TAnchors() << akRight << akBottom;
}
//---------------------------------------------------------------------------

 

 
 

Home Copyright © 2004-2007 FunctionX, Inc.