Scrolling with Dial Pad on SmartPhone

NETCF V2 adds the AutoScroll feature, showing scrollbars on a form when one of its controls is outside the visible region of the form. To enable auto scrolling, simply set the AutoScroll property of the form to true. To change the visible region of the form, you just need to click the buttons of the scrollbars on a Pocket PC or Windows CE device.

What about SmartPhone? Most SmartPhones do not have a touch screen, so there needs to be an alternative way to scroll the form. The way to scroll a form on a SmartPhone is to handle the keyboard inputs by providing an event handler to the form's KeyDown event:

this.KeyDown += new KeyEventHandler(key_Down);

 private void key_Down(object o, KeyEventArgs e){   if ((e.KeyCode == System.Windows.Forms.Keys.Up))   {      this.AutoScrollPosition = new Point(         -this.AutoScrollPosition.X,          -this.AutoScrollPosition.Y - 16);   }   if ((e.KeyCode == System.Windows.Forms.Keys.Down))   {      this.AutoScrollPosition = new Point(         -this.AutoScrollPosition.X,          -this.AutoScrollPosition.Y + 16);   }   if ((e.KeyCode == System.Windows.Forms.Keys.Left))   {      this.AutoScrollPosition = new Point(         -this.AutoScrollPosition.X - 16,          -this.AutoScrollPosition.Y);   }   if ((e.KeyCode == System.Windows.Forms.Keys.Right))   {      this.AutoScrollPosition = new Point(         -this.AutoScrollPosition.X + 16,          -this.AutoScrollPosition.Y);   }}
 This will allow scrolling the form with the dial pad while the form is focused.

How about if the form is not focused? Sometimes the control in focus might be a PictureBox object, or a UserControl. In these cases, simply add the event handler we created earlier to the KeyDown event of the control:

this.pb.KeyDown += new KeyEventHandler(key_Down);

This will provide scrolling with the dial pad while either the form or the control is focused.

Cheers,

Anthony

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