how to set scroll position programatically

閲覧: 455 回
最初の未読メッセージにスキップ

Microsoft

未読、
2003/02/21 20:25:072003/02/21
To:
The ScrollableControl has a ScrollControlIntoView() method, but it's not for
use by users of the class. I have a Panel that I add child controls to
programatically. I would like to set the scroll position so that the last
control added is visible, without user interaction. How can I do this?
Thanks.

tuan


Windows Forms Team

未読、
2003/02/24 17:12:292003/02/24
To:
I know the MSDN documentation says that this method is part of the "internal
infrastructure", but as far as I know, its perfectly safe to call this
method. This could be a documentation error.

- Daniel Lehenbauer

--

Windows Forms Team

This posting is provided "AS IS" with no warranties, and confers no rights.

"Microsoft" <tu...@svisionllc.com> wrote in message
news:#8YEsBh2...@TK2MSFTNGP09.phx.gbl...

Tuan Phan

未読、
2003/02/24 18:28:222003/02/24
To:
Thanks. That worked. I just have to take into account that the function
will modify AutoScrollPosition and compensate for it when I add subsequent
children.

tuan

"Windows Forms Team" <wfc...@microsoft.com> wrote in message
news:uHSTSHF3...@TK2MSFTNGP10.phx.gbl...

Windows Forms Team

未読、
2003/02/26 16:36:062003/02/26
To:
Yes. It is an doc error that in version 1.0, the docs say that the
ScrollControlIntoView is an infrastructure member. Here is the latest
documentation for this member:

**Scrolls the specified control into view on an auto-scroll enabled control.
[Visual Basic]
Public Sub ScrollControlIntoView( _
ByVal activeControl As Control _
)
[C#]
public void ScrollControlIntoView(
Control activeControl
);
**Parameters
activeControl
The control to scroll into view.
**Remarks
The AutoScroll property must be set to true, and at least one of the
scroll bars, horizontal or vertical, must also be visible, for the
ScrollControlIntoView method to have an effect. To make the horizontal and
vertical scroll bars visible, the HScroll and VScroll properties,
respectively, must be set to true.
**Example
The following example enables auto-scrolling for a form, resizes the form,
and ensures that a button remains visible after the form is resized. This
example assumes that you have a Form with a Button named button2 on it.
[Visual Basic]
Private Sub ResizeForm()
' Enable auto-scrolling for the form.
Me.AutoScroll = True

' Resize the form.
Dim r As Rectangle = Me.ClientRectangle
' Subtract 100 pixels from each side of the Rectangle.
r.Inflate(- 100, - 100)
Me.Bounds = Me.RectangleToScreen(r)

' Make sure button2 is visible.
Me.ScrollControlIntoView(button2)
End Sub
[C#]
private void ResizeForm()
{
// Enable auto-scrolling for the form.
this.AutoScroll = true;

// Resize the form.
Rectangle r = this.ClientRectangle;
// Subtract 100 pixels from each side of the Rectangle.
r.Inflate(-100, -100);
this.Bounds = this.RectangleToScreen(r);

// Make sure button2 is visible.
this.ScrollControlIntoView(button2);
}

Mark Rideout

--

Windows Forms Team

This posting is provided "AS IS" with no warranties, and confers no rights.

"Tuan Phan" <tu...@svisionllc.com> wrote in message
news:ueU5auF3...@TK2MSFTNGP11.phx.gbl...

全員に返信
投稿者に返信
転送
新着メール 0 件