Practical
Learning: Implementing Checked Speed Buttons
|
|
- Change the characteristics of the speed buttons as follows:
Control |
AllowUp |
GroupIndex |
sbtOperand1 |
True |
12 |
sbtOperand2 |
True |
14 |
sbtOperation |
True |
16 |
- Double-click the top-left speed button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::sbtOperand1Click(TObject *Sender)
{
if( sbtOperand1->Down == true )
sbtOperand1->Caption = L"True";
else
sbtOperand1->Caption = L"False";
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the top-center speed button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::sbtOperand2Click(TObject *Sender)
{
if( sbtOperand2->Down == true )
sbtOperand2->Caption = L"True";
else
sbtOperand2->Caption = L"False";
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the top-right speed button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::sbtResultClick(TObject *Sender)
{
if( sbtResult->Down == true )
sbtResult->Caption = L"True";
else
sbtResult->Caption = L"False";
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the New Operation button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::btnNewOperationClick(TObject *Sender)
{
UnicodeString strBooleanValues[] = { "True", "False" };
UnicodeString strOperations[] = { "A ^ B", "A V B" };
sbtOperand1->Caption = strBooleanValues[Random(2)];
sbtOperand2->Caption = strBooleanValues[Random(2)];
if( sbtOperand1->Caption == L"True" )
sbtOperand1->Down = true;
else
sbtOperand1->Down = false;
if( sbtOperand2->Caption == L"True" )
sbtOperand2->Down = true;
else
sbtOperand2->Down = false;
sttOperation->Caption = strOperations[Random(2)];
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the Checkl button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::btnCheckClick(TObject *Sender)
{
// Logical Conjunction
if( sttOperation->Caption == "A ^ B" )
{
// If A = true
if( sbtOperand1->Down == true )
{
if( sbtOperand2->Down == true )
{
if( sbtResult->Down == true )
{
// | A | B | A ^ B |
// | T | T | T |
ShowMessage(L"Bravo - Good Answer");
}
else if( sbtResult->Down == false )
{
// | A | B | A ^ B |
// | T | T | F |
ShowMessage(L"Wrong - Get it right next time!");
}
}
else if( sbtOperand2->Down == false )
{
if (sbtResult->Down == false)
{
// | A | B | A ^ B |
// | T | F | F |
ShowMessage(L"Bravo - Good Answer");
}
else if (sbtResult->Down == true)
{
// | A | B | A ^ B |
// | T | F | T |
ShowMessage(L"Wrong - Get it right next time!");
}
}
}
else if( sbtOperand1->Down == false )
{
if( sbtOperand2->Down == true )
{
if( sbtResult->Down == false )
{
// | A | B | A ^ B |
// | F | T | F |
ShowMessage(L"Bravo - Good Answer");
}
else if (sbtResult->Down == true )
{
// | A | B | A ^ B |
// | F | T | T |
ShowMessage(L"Wrong - Get it right next time!");
}
}
else if( sbtOperand2->Down == false )
{
if (sbtResult->Down == false)
{
// | A | B | A ^ B |
// | F | F | F |
ShowMessage(L"Bravo - Good Answer");
}
else if (sbtResult->Down == true)
{
// | A | B | A ^ B |
// | F | F | T |
ShowMessage(L"Wrong - Get it right next time!");
}
}
}
}
else if( sttOperation->Caption == "A V B") // Logical Disjunction:
{
// If A = true
if( sbtOperand1->Down == true)
{
if( sbtOperand2->Down == true)
{
if( sbtResult->Down == true)
{
// | A | B | A V B |
// | T | T | T |
ShowMessage(L"Bravo - Good Answer");
}
else if (sbtResult->Down == false)
{
// | A | B | A V B |
// | T | T | F |
ShowMessage(L"Wrong - Get it right next time!");
}
}
else if (sbtOperand2->Down == false)
{
if (sbtResult->Down == true)
{
// | A | B | A V B |
// | T | F | T |
ShowMessage(L"Bravo - Good Answer");
}
else if (sbtResult->Down == false)
{
// | A | B | A V B |
// | T | F | F |
ShowMessage(L"Wrong - Get it right next time!");
}
}
}
else if (sbtOperand1->Down == false)
{
if (sbtOperand2->Down == true)
{
if( sbtResult->Down == true)
{
// | A | B | A V B |
// | F | T | T |
ShowMessage(L"Bravo - Good Answer");
}
else if( sbtResult->Down == false)
{
// | A | B | A V B |
// | F | T | F |
ShowMessage(L"Wrong - Get it right next time!");
}
}
else if( sbtOperand2->Down == false)
{
if( sbtResult->Down == false)
{
// | A | B | A V B |
// | F | F | F |
ShowMessage(L"Bravo - Good Answer");
}
else if( sbtResult->Down == true)
{
// | A | B | A V B |
// | F | F | T |
ShowMessage(L"Wrong - Get it right next time!");
}
}
}
}
}
//---------------------------------------------------------------------------
- Return to the form
- Double-click the Close button
- Implement its event as follows:
//---------------------------------------------------------------------------
void __fastcall TfrmBoolean::btnCloseClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
- Press F9 to test the application
- Click the New Operation button. Here is an example
- Click the top-right speed to express your answer
- Click the Check button. Here is an example:
- Perform another operation and check it
- Close the form and return to your programming environment
The Flat property can be used to
enhance the appearance of a checked speed button. If you set it to True,
when the control is not checked, it appears completely flat. In fact, if the
control doesn't have a caption (or a picture), it would appear invisible.
Only when the mouse is positioned on top of the control would it signal its
presence.
The Glyphs of a Speed Button
|
|
If you plan to use a bitmap on the speed button, its
Glyph, its Spacing, its NumGlyphs,
its Margin, and its Layout properties
function similar to the same properties of the bitmap button. The
Glyph property of the speed button provides a small addition. Like
the bitmap button, the speed button can use a bitmap made of one or more
glyphs. Unlike the bitmap button, the speed button can use up to four glyphs
and here is how they work:
- If the bitmap contains 1 glyph, this single bitmap would always be
used except when the button is disabled. The operating system is in
charge of displaying or painting the face of the button when it is
disabled
- If the bitmap contains 2 glyphs, the first glyph would be used both
when the button is clicked or down and when the button is not clicked or
is not down. The second glyph would be used when the button is disabled
- If the bitmap contains 3 glyphs, the first would be used when the
button displays normally. The second glyph would display when the button
is disabled. The third glyph would display while the button is down when
it has been clicked
- If the bitmap contains 4 glyphs, this style is valid only if the
button is a member of a group (like radio buttons). The first would be
used when the button displays normally. The second glyph would display
when the button is disabled. The third glyph would display while the
button is down when it has been clicked, exactly like the button with a
NumGlyphs value equal to 3 but with the following exception. If
the button is a member of a group, the third glyph would display while
the mouse is still “pushing” it; that is, while the button is down but
held by the mouse. The fourth glyph is used only if the button is part
of a group and when it is down after the mouse has been released
|
|