Export (0) Print
Expand All

ScrollableControl.AutoScrollPosition Property

Gets or sets the location of the auto-scroll position.

[Visual Basic]
Public Property AutoScrollPosition As Point
[C#]
public Point AutoScrollPosition {get; set;}
[C++]
public: __property Point get_AutoScrollPosition();
public: __property void set_AutoScrollPosition(Point);
[JScript]
public function get AutoScrollPosition() : Point;
public function set AutoScrollPosition(Point);

Property Value

A Point object that represents the auto-scroll position in pixels.

Remarks

The AutoScrollPosition property is used to adjust the position of controls contained on the scrollable control.

When adding controls to a scrollable control the x-coordinate and y-coordinate of the AutoScrollPosition must be added to or subtracted as an offset from the corresponding coordinates of the Control.Location property of the control being added. To add a control above or to the left of the scroll position, the offset must be added to the desired location. Alternatively, to add a control below or to the right of the scroll position, the offset must be subtracted.

Note    AutoScrollPosition represents the location of the scrollable control's display rectangle. The X and Y coordinate values retrieved are negative if the control has scrolled away from its starting position (0,0). However, when setting this property, you must assign positive X and Y values to scroll away from the starting position and negative values to move toward it.

Example

[Visual Basic, C#, C++] The following example uses the ScrollableControl derived class Panel and adds a button to the upper left corner of the scrollable area. The example allows for the offset determined by the AutoScrollPosition. This example assumes you have a Form that contains a Panel with a Button on it. To enable auto-scrolling, you should place the button outside of the client area of the Panel.

[Visual Basic] 
Private Sub button1_Click(sender As Object, _
   e As EventArgs) Handles button1.Click
   ' Add a button to top left corner of the 
   ' scrollable area, allowing for the offset. 
   panel1.AutoScroll = True
   Dim myButton As New Button()
   myButton.Location = New Point( _
      0 + panel1.AutoScrollPosition.X, _
      0 + panel1.AutoScrollPosition.Y)
   panel1.Controls.Add(myButton)
End Sub

[C#] 
private void button1_Click(object sender, EventArgs e)
{
   /* Add a button to top left corner of the 
    * scrollable area, allowing for the offset. */
   panel1.AutoScroll = true;
   Button myButton = new Button();
   myButton.Location = new Point(
      0 + panel1.AutoScrollPosition.X, 
      0 + panel1.AutoScrollPosition.Y);
   panel1.Controls.Add(myButton);
}

[C++] 
private:
   void button1_Click(Object* /*sender*/, EventArgs* /*e*/) {
      /* Add a button to top left corner of the
      * scrollable area, allowing for the offset. */
      panel1->AutoScroll = true;
      Button* myButton = new Button();
      myButton->Location =  Point(
         0 + panel1->AutoScrollPosition.X,
         0 + panel1->AutoScrollPosition.Y);
      panel1->Controls->Add(myButton);
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ScrollableControl Class | ScrollableControl Members | System.Windows.Forms Namespace | AutoScroll | AutoScrollMargin | AutoScrollMinSize

Show:
© 2014 Microsoft