Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Propriedade ScrollableControl.AutoScrollPosition

 

Obtém ou define o local da posição de rolagem automática.

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

[BrowsableAttribute(false)]
public Point AutoScrollPosition { get; set; }

Valor da Propriedade

Type: System.Drawing.Point

Um Point que representa a posição de rolagem automática em pixels.

The P:System.Windows.Forms.ScrollableControl.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 P:System.Windows.Forms.ScrollableControl.AutoScrollPosition property to position the control either inside or outside of the current viewable scroll area.

System_CAPS_noteObservação

The P:System.Drawing.Point.X and P:System.Drawing.Point.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 P:System.Drawing.Point.X and P:System.Drawing.Point.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, P:System.Windows.Forms.ScrollableControl.AutoScrollPosition returns {-200, 0}; in the second case, it returns {-100,0}.

To detect when P:System.Windows.Forms.ScrollableControl.AutoScrollPosition changes, create an event handler for the E:System.Windows.Forms.Control.Paint event, save the old position value in a private variable, and compare the new value to the old value on subsequent E:System.Windows.Forms.Control.Paint events.

The following code example uses the T:System.Windows.Forms.ScrollableControl derived class T:System.Windows.Forms.Panel and adds a button to the upper left corner of the scrollable area. The example allows for the offset determined by the P:System.Windows.Forms.ScrollableControl.AutoScrollPosition. The example was written under the assumption that you have a T:System.Windows.Forms.Form that contains a T:System.Windows.Forms.Panel with a T:System.Windows.Forms.Button on it. To enable auto-scrolling, place the button outside of the client area of the T:System.Windows.Forms.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 = new Button();
   myButton.Location = new Point(
      0 + panel1.AutoScrollPosition.X, 
      0 + panel1.AutoScrollPosition.Y);
   panel1.Controls.Add(myButton);
}

.NET Framework
Disponível desde 1.1
Retornar ao início
Mostrar: