Export (0) Print
Expand All

ScrollableControl.AutoScrollPosition Property

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[<BrowsableAttribute(false)>]
member AutoScrollPosition : Point with get, set

Property Value

Type: System.Drawing.Point
A Point that represents the auto-scroll position in pixels.

The AutoScrollPosition property represents the location of the visible portion of a scrollable control. Use this property to change the portion of the control that is displayed.

When adding controls programmatically to a form, use the AutoScrollPosition property to position the control either inside or outside of the current viewable scroll area.

NoteNote

The X and Y coordinate values retrieved are negative if the control has scrolled away from its starting position (0,0). When you set this property, you must always assign positive X and Y values to set the scroll position relative to the starting position. For example, if you have a horizontal scroll bar and you set x and y to 200, you move the scroll 200 pixels to the right; if you then set x and y to 100, the scroll appears to jump the left by 100 pixels, because you are setting it 100 pixels away from the starting position. In the first case, AutoScrollPosition returns {-200, 0}; in the second case, it returns {-100,0}.

To detect when AutoScrollPosition changes, create an event handler for the Paint event, save the old position value in a private variable, and compare the new value to the old value on subsequent Paint events.

The following code 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. The example was written under the assumption that you have a Form that contains a Panel with a Button on it. To enable auto-scrolling, place the button outside of the client area of the Panel.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft