ScrollableControl.AutoScrollPosition 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定自動捲動位置的位置。
public:
property System::Drawing::Point AutoScrollPosition { System::Drawing::Point get(); void set(System::Drawing::Point value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point AutoScrollPosition { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.AutoScrollPosition : System.Drawing.Point with get, set
Public Property AutoScrollPosition As Point
屬性值
A Point 代表以像素為單位的自動捲動位置。
- 屬性
範例
以下程式碼範例使用 ScrollableControl 衍生類別 Panel ,並在可捲動區域的左上角新增一個按鈕。 本範例允許由 決定 AutoScrollPosition的偏移量。 這個範例是在假設你有一個 Form 包含 a Panel 且帶有 a Button 的前提下撰寫的。 要啟用自動捲動,請將按鈕放在 Panel.
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 = gcnew Button;
myButton->Location = Point(0 + panel1->AutoScrollPosition.X,0 + panel1->AutoScrollPosition.Y);
panel1->Controls->Add( myButton );
}
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);
}
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
備註
屬性 AutoScrollPosition 代表可捲動控制項可見部分的位置。 使用此屬性來更改顯示控制項的部分。
在程式化新增控制項到表單時,請使用該 AutoScrollPosition 屬性將控制項置於當前可檢視捲動區域的內側或外側。
備註
X Y若控制項已從起始位置(0,0)滾動,則取回的座標值為負值。 當你設定這個屬性時,必須總是指派 正 X 數和 Y 數值來設定捲動位置相對於起始位置。 舉例來說,如果你有一個水平捲動條,並且將 x 和 y 設為 200,你就會將捲動向右移動 200 像素;如果你把 x 和 y 設為 100,捲動看起來會向左跳 100 像素,因為你設定在離起始位置 100 像素的地方。 第一種情況下,返回 AutoScrollPosition {-200, 0};在第二種情況下,返回 {-100,0}。
要偵測變動時 AutoScrollPosition ,請為事件建立事件處理程序 Paint ,將舊位置值儲存在私有變數中,並在後續 Paint 事件中將新值與舊值比較。