RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TControlScrollBar.Margin Property

Determines when a scroll bar is generated.

Pascal
property Margin: Word;
C++
__property Word Margin;

The Margin property determines the minimum number of pixels that must separate each control from the edge of the control that uses the scroll bar. At runtime, whenever a child control is less than Margin pixels from the edge and Visible is set to true, a scroll bar appears.  

C++ Examples: 

 

/*
This example uses a button and a label on a form and needs
the AutoScroll property set on the form. Place the label
near the left side of the form, and place the button
somewhere near the middle of the form. When the user runs
the application, a horizontal scroll bar does not appear,
because no control on the form is close enough to the right
edge.  Each time the user clicks the button, the button moves
25 pixels to the right, and the calculated Range value is
reported in the caption of the label. Repeatedly clicking the
button eventually moves the button close enough to the edge
of the form (within the Margin amount) so that a horizontal 
scroll bar appears.  Note that the Range property is 
continuously updated as the button moves to the right.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Button1->Left = Button1->Left + 25;
  Label1->Caption = IntToStr(HorzScrollBar->Range);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  HorzScrollBar->Margin = 25;
  HorzScrollBar->Increment = 10;
}

 

Delphi Examples: 

{
This example uses a button and a label on a form and needs
the AutoScroll property set on the form. Place the label
near the left side of the form, and place the button
somewhere near the middle of the form. When the user runs
the application, a horizontal scroll bar does not appear,
because no control on the form is close enough to the right
edge.  Each time the user clicks the button, the button moves
25 pixels to the right, and the calculated Range value is
reported in the caption of the label. Repeatedly clicking the
button eventually moves the button close enough to the edge
of the form (within the Margin amount) so that a horizontal 
scroll bar appears.  Note that the Range property is 
continuously updated as the button moves to the right.
}
procedure TForm1.FormCreate(Sender: TObject);
begin
  with HorzScrollBar do
  begin
    Margin:= 25;
    Increment := 10;
    Visible := True;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Left := Button1.Left + 25;
  Label1.Caption := IntToStr(HorzScrollBar.Range);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!