Export (0) Print
Expand All

How to: Scroll a Form of Labels

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Because a Label control does not receive the focus and does not support tabbing, a Smartphone application of only Label controls does not allow the user to navigate to labels beyond the visible client area of the form. The user of a Pocket PC application can tap the scroll bars to navigate, but this capability is not available on the Smartphone.

You can implement navigation by providing code in the event handler for the KeyDown event that adjusts the AutoScrollPosition property.

To scroll a form of Label controls

  1. Add several Label controls to the form so that some are below the visible client area. Use arrow keys in the Microsoft Visual Studio 2005 designer or write initialization code to position them.

  2. In the form's constructor, set the KeyPreview and AutoScroll properties to true. C# users must attach a delegate for the KeyDown event handler.

    
    this.KeyPreview = true;
    this.KeyDown += new KeyEventHandler(Form1_KeyDown);
    this.AutoScroll = true;
    
    
    
  3. Set the AutoScrollPosition property to move vertically by a set number of pixels for the y point coordinate. The following code example uses 16. Note that the code is complex because AutoScrollPosition is offset by negative values, but the provided point values must be expressed as positive.

    
    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if ((e.KeyCode == System.Windows.Forms.Keys.Up))
        {
            this.AutoScrollPosition = new Point(0, -this.AutoScrollPosition.Y - 16);
        }
        if ((e.KeyCode == System.Windows.Forms.Keys.Down))
        {
            this.AutoScrollPosition = new Point(0, -this.AutoScrollPosition.Y + 16);
        }
    
    
    

This example requires references to the following namespaces:

Show:
© 2014 Microsoft