Characteristics of a Command Link Button
|
|
Besides the regular caption, you can add a sentence
under it. To support this, the TCustomButton class provides the
CommandLinkHint property, which is a string:
__property System::UnicodeString CommandLinkHint =
{
read=FCommandLinkHint,
write=SetCommandLinkHint
};
To visually specify the hint, access the Object
Inspector for the button and type the desired string in the CommandLinkHint
field:
This would produce:
When a command link has focus, it shows some borders.
This is also the case if the button appears by itself in a form. When there
are more than one button, the button that has focus shows some borders and
the other button does not. When the mouse passes over the button that
doesn't have focus, its borders are raised.
Practical
Learning: Specifying the Hit Link
|
|
- Click the Angle Evaluations button
- In the Object Inspector, click CommandHitLink, type Find the
trigonometric values of a known constant and press Enter
- In the same way, change the CommandHitLink property of the Right
Triangle Calculations button to Knowing the 3 sides of a right
triangle, find the values of both acute angles
- In the same way, change the CommandHitLink property of the Close
button to Close the application
- Double-click the Angle Evaluations button and implement its event as
follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnAngleEvaluationsClick(TObject *Sender)
{
pnlAngleEvaluations->Visible = True;
grpAlpha->Visible = True;
pnlRightTriangle->Visible = False;
grpTheta->Visible = False;
pnlValue->Visible = False;
}
//---------------------------------------------------------------------------
- Return to the form and double-click an unoccupied area of its body
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::FormCreate(TObject *Sender)
{
btnAngleEvaluationsClick(Sender);
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select
btnCalculateAngle
- Click Events
- Double-click OnClick and implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnCalculateAngleClick(TObject *Sender)
{
double Value = 0.00,
Sine = 0.00, Cosine = 0.00, Tangent = 0.00;
// Retrieve the value
Value = StrToFloat(edtAngleValue->Text);
// Calculate
Sine = sin(Value);
Cosine = cos(Value);
Tangent = tan(Value);
// Display the values
this->ledAngleSine->Text = FloatToStr(Sine);
this->ledAngleCosine->Text = FloatToStr(Cosine);
this->ledAngleTangent->Text = FloatToStr(Tangent);
if( Value != 0.00 )
this->ledAngleSecant->Text = FloatToStr(1 / Sine);
this->ledAngleCosecant->Text = FloatToStr(1 / Cosine);
if( Value != 0.00 )
this->ledAngleCotangent->Text = FloatToStr(1 / Tangent);
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the Right Triangle Calculations button and implement
its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnRightTriangleClick(TObject *Sender)
{
pnlRightTriangle->Visible = True;
pnlAngleEvaluations->Visible = False;
grpAlpha->Visible = True;
pnlAngleValues->Visible = False;
grpTheta->Visible = False;
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select btnAlpha
- Double-click OnClick and implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnAlphaClick(TObject *Sender)
{
double a = 0.00, b = 0.00, c = 0.00;
double Alpha = 0.00;
double Theta = 0.00;
a = StrToFloat(ledA->Text);
b = StrToFloat(ledB->Text);
c = StrToFloat(ledC->Text);
this->grpAlpha->Visible = True;
this->grpTheta->Visible = False;
this->ledAlphaSine->Text = FloatToStr(b / c);
this->ledAlphaCosine->Text = FloatToStr(a / c);
this->ledAlphaTangent->Text = FloatToStr(b / a);
this->ledAlphaCosecant->Text = FloatToStr(c / b);
this->ledAlphaSecant->Text = FloatToStr(c / a);
this->ledAlphaCotangent->Text = FloatToStr(a / b);
}
//---------------------------------------------------------------------------
- In the top combo box of the Object Inspector, select btnTheta
- Double-click OnClick and implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnThetaClick(TObject *Sender)
{
double a = 0.00, b = 0.00, c = 0.00;
double Alpha = 0.00;
double Theta = 0.00;
a = StrToFloat(ledA->Text);
b = StrToFloat(ledB->Text);
c = StrToFloat(ledC->Text);
this->grpTheta->Visible = True;
this->grpAlpha->Visible = False;
this->ledThetaSine->Text = FloatToStr(a / c);
this->ledThetaCosine->Text = FloatToStr(b / c);
this->ledThetaTangent->Text = FloatToStr(a / b);
this->ledThetaCosecant->Text = FloatToStr(c / a);
this->ledThetaSecant->Text = FloatToStr(c / b);
this->ledThetaCotangent->Text = FloatToStr(b / a);
}
//---------------------------------------------------------------------------
- Press F12 to display the form
- Double-click the Close button and implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmCalculations::btnCloseClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
- Save all
- Press F9 to execute the application
- Enter a position value in the edit control and click Calculate:
- Click the Right Triangle button
- Enter some values in the a, the b, and the c edit boxes
- Click Alpha
- Enter new values in the a, the b, and the c edit boxes
- Click Theta
- Close the form and return to your programming environment
The defualt picture of a command link button appears as
a green right-pointing icon. If you want to change it, first create an image
list and assign it to the Images property of the button. To
specify what picture to use, assign the index to the ImageIndex property.
That image would appear on the button when the control doesn't have focus or
when it looses focus. One of the options you have it to display a different
picture when the button has focus but without being clicked. To support
this, the TCustomButton class provides the SelectedImageIndex
property:
__property int SelectedImageIndex =
{
read=FSelectedImageIndex,
write=SetSelectedImageIndex
};
This property is of type int. To specify its value
assign the desired index from the image list. Another option is to specify
what picture to show when the button is pressed. This is done using the
PressedImageIndex proeprty:
__property int PressedImageIndex = {read=FPressedImageIndex,write=SetPressedImageIndex};
This property also uses an index from the image list.
|
|