Home

Windows Controls: The Scroll Box

   

Introduction to Scroll Boxes

 

Description

A scroll box is a container control that is used to hold one or more items that need more space but that space is not available. As a result, if necessary, the scroll box may be equipped with one or more scroll bars. You don't create the scroll bar(s). The operating system performs some calculations to determine whether the scroll bar(s) is (are) needed to show the hidden area(s).

Practical LearningPractical Learning: Introducing Scroll Bars

  1. Start Embarcadero RAD Studio
  2. To start a new application, on the main menu, click File -> New -> VCL Forms Application - C++Builder
  3. While the default form is displaying, press F12 to display its code
  4. Right-click the Code Editor and click Close Page
  5. When asked whether you want to save, click No
  6. To add a new form, on the Standard toolbar, click the New Items button New Items
  7. In the left list of the New Items dialog box, click C++Builder Files
  8. In the right list, click Tabbed Pages
     
    Tabbed Pages
  9. Click OK
  10. Press F12 to display the dialog box
  11. In the Structures window, click PagesDlg to make sure the dialog box is selected.
    In the Object Inspector, change the following properties:
    Caption: Algebra
    Name: dlgAlgebra
  12. On the dialog box, click the body of TabSheet1
  13. In the Object Inspector, change the following properties:
    Caption: Properties of Real Numbers
    Name: tabRealNumbersProperties
  14. In the body of the left tab sheet, add the following controls:
     
    Algebra
    Control Caption Font Shape
    Font Size Font Style Color  
    TPanel TPanel            
    TLabel TLabel Let R be the set of all real numbers Garamond 12 Bold Maroon  
    TLabel TLabel Let x, y, and z be arbitrary variables in R Garamond 12 Bold Maroon  

Creating a Scroll Box

To support scroll boxes, the VCL provides the TScrollBox class that is represented in the Tool Palette by a control of the same name. The TScrollBox class is derived from TScrollingWinControl:

TScrollBox Inheritance

To visually create a scroll box, in the Additional section of the Tool Palette, click the TScrollBox icon TScrollBox and click the form. To programmatically create a scroll box, declare a variable of type TScrollBox and allocate memory for it using the new operator. Using its constructor and its Parent property, specify both its owner and its parent. Here is an example: 

//---------------------------------------------------------------------------
void __fastcall TForm1::btnScrollBoxClick(TObject *Sender)
{
	TScrollBox *sbxContainer = new TScrollBox(Form1);
	sbxContainer->Parent = Form1;
}
//---------------------------------------------------------------------------

Practical LearningPractical Learning: Creating a Scroll Box

  1. In the Tool Palette, click Additional and click the TScrollBox icon TScrollBox
  2. Click the body of the first tab sheet on the dialog box under the existing panel
  3. Resize it to use the whole width of the tab sheet
     
    Algebra
 
 
 

Characteristics of a Scroll Box

 

Introduction

The scroll box is a classic implementor of a scrolling window. In fact, all the functionalities of a scroll box come from its ancestors, first from the TWinControl class, and especially from TScrollingWinControl. Because the scroll box is primarily a visual Windows control, it has characteristics that allow it to have presence. For example, you should make sure you control the size of the scroll box using its Width and Height properties.

As a child of the TScrollingWinControl class, a scroll box can be equipped with one or both scroll bars. As described for a scroll bar, a scroll box relies on the operating system to decide whether a scroll bar is needed on the container, based on the controls it is hosting. Your role is to add the objects to the scroll box and give them the sizes you feel necessary for the functionality of your application.

Practical LearningPractical Learning: Creating a Scroll Box

  1. In the body of the scroll box, add the following controls:
     
    Algebra
    Control Caption Font Shape
    Font Size Font Style Color  
    TLabel TLabel Addition Georgia 14 Bold Blue  
    TBevel TLabel           bsBottomLine
    TLabel TLabel Closure: Georgia 10      
    TLabel TLabel x + y is a unique value in R Georgia 10      
    TLabel TLabel Associative: Georgia 10      
    TLabel TLabel (x + y) + z = x + (y + z) Georgia 10      
    TLabel TLabel Commutative: Georgia 10      
    TLabel TLabel x + y = y + z Georgia 10      
    TLabel TLabel Identity: Georgia 10      
    TLabel TLabel x + 0 = 0 + x = x Georgia 10      
    TLabel TLabel Inverse Georgia 10      
    TLabel TLabel x + (-x) = (-x) + x = 0 Georgia 10      
  2. Click the Addition label
  3. Press and hold Shift
  4. Click the bevel and click each of the labels under it
  5. Release Shift
     
    Algebra
  6. On the main menu, click Edit -> Copy
  7. Click an empty area in the scroll box to make sure nothing is selected
  8. On the main menu, click Edit -> Paste
  9. While the controls are selected (there is a mixture of selected and unselected controls:
     
    Algebra

    so you must make sure you can carefully identify a control that is selected), click one of them and hold the mouse down
  10. Drag down to position the selection under the existing controls. You can first dra half-way, release the mouse, scroll down using the right scroll bar of the scroll box, and drag the selection down again
  11. Click an unoccupied are on the form to make sure nothing is selected
  12. Change the captions of the labels as follows:
     
    Algebra
    Control Caption
    TLabel TLabel Multiplication
    TBevel TLabel  
    TLabel TLabel Closure:
    TLabel TLabel xy is a unique value in R
    TLabel TLabel Associative:
    TLabel TLabel (xy)z = x(yz)
    TLabel TLabel Commutative:
    TLabel TLabel xy = yz
    TLabel TLabel Identity:
    TLabel TLabel x(1) = (1)x = x
    TLabel TLabel Inverse
    TLabel TLabel x(1/x) = (1/x)x = 1
  13. Double-click the Cancel button and implement its event as follows:
    //---------------------------------------------------------------------
    void __fastcall TdlgAlgebra::CancelBtnClick(TObject *Sender)
    {
    	Close();
    }
    //---------------------------------------------------------------------------
  14. Press F9 to test the application
     
    Algebra
     
    Algebra
  15. Close the form and return to your programming environment

The Border Style

The only characteristic that the VCL's scroll box has on its own is the ability to show or hide its borders. This is handled by the BorderStyle property of the TScrollBox class:

__property Forms::TFormBorderStyle BorderStyle = {read=FBorderStyle,write=SetBorderStyle};

The border style is a derivative of the TFormBorderStyle enumerator:

typedef Forms::TFormBorderStyle TBorderStyle;

This property has only two values:

  • bsSingle: With this value, the scroll box gets equipped with 3-D border
  • bsNone: The scroll box does not show borders
 
 
   
 

Home Copyright © 2010-2016, FunctionX