RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TControlScrollBar.Position Property

Specifies the position of the thumb tab on the scroll bar.

Pascal
property Position: Integer;
C++
__property int Position;

Use Position to programmatically scroll the client area of the associated control. The value of Position changes (from 0 to Range) at runtime as the user scrolls the scroll bar.  

C++ Examples: 

 

/*
This example starts the form in a position scrolled so that
the right hand edge shows:
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  /* set the width of the form window to display 300 pixels in the client area */
  ClientWidth = 300;
  /* now set the range to twice the client width.
   This means that the form has a logical size
   that is twice as big as the physical window.
   Note that Range must always be at least as big as ClientWidth! */
  HorzScrollBar->Range = 600;
  /* start the form fully scrolled */
  HorzScrollBar->Position = HorzScrollBar->Range - ClientWidth;
  /* clicking the scroll arrows moves the form 10 pixels */
  HorzScrollBar->Increment = 10;
  HorzScrollBar->Visible = true;  // Show the scrollbar
}
/*
The following example demonstrates form scrolling with the
PgUp and PgDn keys.
*/
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
  const int iPageDelta = 10;

  if (Key == VK_NEXT)
    VertScrollBar->Position += iPageDelta;
  else if (Key == VK_PRIOR)
    VertScrollBar->Position -= iPageDelta;
}

 

Delphi Examples: 

{
This example starts the form in a position scrolled so that
the right hand edge shows:
}
procedure TForm1.FormCreate(Sender: TObject);
begin
  ClientWidth := 300;
  with HorzScrollBar do
  begin
    { Set the range to twice the ClientWidth of the form }
    { This means that the form’s logical size is twice as big }
    { as the physical window. }
    { Note that Range must always be larger than the ClientWidth }
    Range := 600; 
    Position := Range - ClientWidth; { start form out fully scrolled }
    Increment := 10;  { clicking the scroll arrows moves the form 10 pixels }
    Visible := True;  { Show the scrollbar }
  end;
end; 

 

{
The following example demonstrates form scrolling with the
PgUp and PgDn keys.
}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
const
  PageDelta = 10;
begin
  With VertScrollbar do
    if Key = VK_NEXT then
      Position := Position + PageDelta
    else if Key = VK_PRIOR then
      Position := Position - PageDelta;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!