ScrollBarMargin (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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 you run the application, a horizontal scroll bar does not appear, because no control on the form is close enough to the right edge. Each time you click the button, it 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.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Button1->Left = Button1->Left + 25;
  Label1->Caption = IntToStr(HorzScrollBar->Range);
}

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  HorzScrollBar->Margin = 25;
  HorzScrollBar->Increment = 10;
}

Uses