PageSize (C++)
Description
The following code sets the thumb tab of a scroll bar so that it represents the proportion of the scrolling range that is visible.
Code
void __fastcall SetThumbTab()
{
// Get the minimum (default) size of the thumb tab.
int MinHeight = GetSystemMetrics(SM_CYVTHUMB);
// Get the size of the scroll bar track
int TrackHeight = Form1->ScrollBar1->ClientHeight - 2*GetSystemMetrics(SM_CYVSCROLL);
// Set PageSize to represent the visible portion of the scrolling range.
Form1->ScrollBar1->PageSize = TrackHeight/(Form1->ScrollBar1->Max - Form1->ScrollBar1->Min + 1);
// Do not let the thumb tab get too small.
if (Form1->ScrollBar1->PageSize < MinHeight)
Form1->ScrollBar1->PageSize = MinHeight;
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
const String Path = L"../overview.rtf";
RichEdit1->PlainText = False;
RichEdit1->Lines->LoadFromFile(Path);
SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichEdit1Change(TObject *Sender)
{
SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
SetThumbTab();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichEdit1EndDrag(TObject *Sender, TObject *Target,
int X, int Y)
{
SetThumbTab();
}
Uses
- Vcl.StdCtrls.TScrollBar.PageSize ( fr | de | ja )