Wednesday, October 24, 2007

Getting a Form to Scroll Down on Smartphone

One problem that I have had with the Compact Framework and Form for Smartphone app (Smartphone 5.0 or Windows Mobile 6 Standard) is that you will get an automatic scroll bar on your form if the form contents go off the screen, but you can't scroll up or down. This problaby is particually a problem if you design a form for one screen size (240x320), but then you run your app on a device like the Motorola Q that has (320x240). The Autoscroll property gets the scroll bar up on the screen, but if there are no tab stop controls, it will not move the form up or down.

The only workaround I have found to solve this problem is to adjust the AutoScrollPosition attribute manually if keys are pressed on the device.


Private Sub Form_GpsInfo_KeyDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If (e.KeyCode = System.Windows.Forms.Keys.Up) Then
'Up
Me.AutoScrollPosition = New Point(-Me.AutoScrollPosition.X, _

-Me.AutoScrollPosition.Y - 16)
End If


If (e.KeyCode = System.Windows.Forms.Keys.Down) Then
'Down
Me.AutoScrollPosition = New Point(-Me.AutoScrollPosition.X,

-Me.AutoScrollPosition.Y + 16)
End If


End Sub

The amount you scroll up or down can be varied.

I found a similar article on this problems at:

http://blogs.msdn.com/anthonywong/archive/2005/05/12/416907.aspx

No comments: