ScrollBar Object

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The ScrollBar object represents scroll bars of windows and controls in scripts. The object is returned by the VScroll and HScroll properties of any window or scroll bar control (for example, SilverlightScrollViewer).

Two notes:

  • The ScrollBar object cannot support scroll bars in ActiveX controls.

  • If the window does not have the intended scroll bar, the minimum, maximum and current positions are all 0.

    JavaFX ScrollPane: If the control does not have a scroll bar, the minimum position will be 0, the maximum position will be 1, and the current position could be changed to any value between the minimum and maximum.

Members

Example

The following example demonstrates how to obtain the tested object’s scroll bar in script, get the maximum and minimum positions of the thumb and change the scroll bar’s current position.

JavaScript, JScript

function TestScrollBar()
{

  var VScrollBar, HScrollBar, Min, Max;
  // Obtains the ScrollBar object corresponding to the tested object’s vertical scroll bar
  VScrollBar = Aliases.TestedApp.TestForm.TextBox.VScroll;

  // Obtains the ScrollBar object corresponding to the tested object’s horizontal scroll bar
  HScrollBar = Aliases.TestedApp.TestForm.TextBox.HScroll;

  // Obtains the bottommost position of the scroll bar thumb
  Max = VScrollBar.Max;
  // Obtains the topmost position of the scroll bar thumb
  Min = VScrollBar.Min;
  // Moves the thumb to the middle of the vertical scroll bar
  VScrollBar.Pos = (Max - Min) / 2;

  // Obtains the rightmost position of the scroll bar thumb
  Max = HScrollBar.Max;
  // Obtains the leftmost position of the scroll bar thumb
  Min = HScrollBar.Min;
  // Moves the thumb to the middle of the horizontal scroll bar
  HScrollBar.Pos = (Max - Min) / 2;

}

Python

def TestScrollBar():
  # Obtains the ScrollBar object corresponding to the tested object's vertical scroll bar 
  VScrollBar = Aliases.TestedApp.TestForm.TextBox.VScroll

  # Obtains the ScrollBar object corresponding to the tested object's horizontal scroll bar 
  HScrollBar = Aliases.TestedApp.TestForm.TextBox.HScroll

  # Obtains the bottommost position of the scroll bar thumb 
  Max = VScrollBar.Max
  # Obtains the topmost position of the scroll bar thumb 
  Min = VScrollBar.Min
  # Moves the thumb to the middle of the vertical scroll bar 
  VScrollBar.Pos = (Max - Min) / 2

  # Obtains the rightmost position of the scroll bar thumb 
  Max = HScrollBar.Max
  # Obtains the leftmost position of the scroll bar thumb 
  Min = HScrollBar.Min
  # Moves the thumb to the middle of the horizontal scroll bar 
  HScrollBar.Pos = (Max - Min) / 2

VBScript

Sub TestScrollBar

  Dim VScrollBar, HScrollBar, Min, Max
  ' Obtains the ScrollBar object corresponding to the tested object’s vertical scroll bar
  Set VScrollBar = Aliases.TestedApp.TestForm.TextBox.VScroll

  ' Obtains the ScrollBar object corresponding to the tested object’s horizontal scroll bar
  Set HScrollBar = Aliases.TestedApp.TestForm.TextBox.HScroll

  ' Obtains the bottommost position of the scroll bar thumb
  Max = VScrollBar.Max
  ' Obtains the topmost position of the scroll bar thumb
  Min = VScrollBar.Min
  ' Moves the thumb to the middle of the vertical scroll bar
  VScrollBar.Pos = (Max - Min) \ 2

  ' Obtains the rightmost position of the scroll bar thumb
  Max = HScrollBar.Max
  ' Obtains the leftmost position of the scroll bar thumb
  Min = HScrollBar.Min
  ' Moves the thumb to the middle of the horizontal scroll bar
  HScrollBar.Pos = (Max - Min) \ 2

End Sub

DelphiScript

procedure TestScrollBar();
var VScrollBar, HScrollBar, Min, Max;
begin

  // Obtains the ScrollBar object corresponding to the tested object’s vertical scroll bar
  VScrollBar := Aliases.TestedApp.TestForm.TextBox.VScroll;

  // Obtains the ScrollBar object corresponding to the tested object’s horizontal scroll bar
  HScrollBar := Aliases.TestedApp.TestForm.TextBox.HScroll;

  // Obtains the bottommost position of the scroll bar thumb
  Max := VScrollBar.Max;
  // Obtains the topmost position of the scroll bar thumb
  Min := VScrollBar.Min;
  // Moves the thumb to the middle of the vertical scroll bar
  VScrollBar.Pos := (Max - Min) / 2;

  // Obtains the rightmost position of the scroll bar thumb
  Max := HScrollBar.Max;
  // Obtains the leftmost position of the scroll bar thumb
  Min := HScrollBar.Min;
  // Moves the thumb to the middle of the horizontal scroll bar
  HScrollBar.Pos := (Max - Min) / 2;

end;

C++Script, C#Script

function TestScrollBar()
{

  var VScrollBar, HScrollBar, Min, Max;
  // Obtains the ScrollBar object corresponding to the tested object’s vertical scroll bar
  VScrollBar = Aliases["TestedApp"]["TestForm"]["TextBox"]["VScroll"];

  // Obtains the ScrollBar object corresponding to the tested object’s horizontal scroll bar
  HScrollBar = Aliases["TestedApp"]["TestForm"]["TextBox"]["HScroll"];

  // Obtains the bottommost position of the scroll bar thumb
  Max = VScrollBar["Max"];
  // Obtains the topmost position of the scroll bar thumb
  Min = VScrollBar["Min"];
  // Moves the thumb to the middle of the vertical scroll bar
  VScrollBar["Pos"] = (Max - Min) / 2;

  // Obtains the rightmost position of the scroll bar thumb
  Max = HScrollBar["Max"];
  // Obtains the leftmost position of the scroll bar thumb
  Min = HScrollBar["Min"];
  // Moves the thumb to the middle of the horizontal scroll bar
  HScrollBar["Pos"] = (Max - Min) / 2;

}

See Also

List of Win32 Controls
Window Object

Highlight search results