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
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Wednesday, October 24, 2007
Sunday, October 21, 2007
Determine Current Screen Orientation for Windows Mobile
To find the Screen Orientation on a Windows Mobile device, you can easily check the screen orientation property. Sample VB.NET code is shown below (C# code would be similar):
Imports Microsoft.WindowsCE.Forms
.
.
.
Dim orientation As ScreenOrientation = _
SystemSettings.ScreenOrientation
Orientation will be:
Imports Microsoft.WindowsCE.Forms
.
.
.
Dim orientation As ScreenOrientation = _
SystemSettings.ScreenOrientation
Orientation will be:
- ScreenOrientation.Angle0
- ScreenOrientation.Angle90
- ScreenOrientation.Angle180
- ScreenOrientation.Angle270
If the Orientation changes while a form is being displayed, the Resize will be fired.
More Info can be found at: http://msdn2.microsoft.com/en-us/library/ms229671.aspx
Friday, October 12, 2007
Getting a List of Storage Card Directories for Smartphone and Windows Mobile
There are lots of example of getting a list of Storage Card directories for Windows Mobile and Smartphone out there. He is one that I have cobbled together from the other example in VB.NET.
Other references that include C# examples are:
http://msdn2.microsoft.com/en-us/library/aa446567.aspx
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=432
Imports System.IO
Public Function GetStorageCardNames() As String()
Try
Dim attrStorageCard As FileAttributes = FileAttributes.Directory Or FileAttributes.Temporary
Dim scards As New ArrayList()
Dim rootDir As New DirectoryInfo("\")
For Each di As DirectoryInfo In rootDir.GetDirectories()
If (di.Attributes And attrStorageCard) = attrStorageCard Then
scards.Add(di.Name)
End If
Next
Return CType(scards.ToArray(GetType(String)), String())
Catch ex As Exception
Return Nothing
End Try
End Function
Other references that include C# examples are:
http://msdn2.microsoft.com/en-us/library/aa446567.aspx
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=432
Imports System.IO
Public Function GetStorageCardNames() As String()
Try
Dim attrStorageCard As FileAttributes = FileAttributes.Directory Or FileAttributes.Temporary
Dim scards As New ArrayList()
Dim rootDir As New DirectoryInfo("\")
For Each di As DirectoryInfo In rootDir.GetDirectories()
If (di.Attributes And attrStorageCard) = attrStorageCard Then
scards.Add(di.Name)
End If
Next
Return CType(scards.ToArray(GetType(String)), String())
Catch ex As Exception
Return Nothing
End Try
End Function
Tuesday, October 9, 2007
Sorting Listviews by Column with the .NET Compact Framework
Sorting a listview by column is not overly complicated on the desktop, but with the Compact Framework is not so straightforward. Here is a good artcle from Microsoft that describes how to accomplish the task:
http://msdn2.microsoft.com/en-us/library/ms229643.aspx
http://msdn2.microsoft.com/en-us/library/ms229643.aspx
Thursday, October 4, 2007
Connecting a Smartphone to a GPS (Window Mobile Smartphone 5.0 and Windows Mobile Standard 6)
It seems to be a little more difficult than it should be to set up a GPS on a Windows Mobile Standard 6 Smartphone. Here is a list of steps that might help:
For Smartphone (Windows Mobile Standard 6):
For Smartphone (Windows Mobile Smartphone 5.0):
from http://blogs.msdn.com/windowsmobile/archive/2006/06/07/620387.aspx
Make sure Bluetooth is set to "On". Menu/Devices Menu/New Select your GPS device from the list and press Next. Enter the passkey for the Bluetooth GPS. For example, 0000 or 0183. Next You should get a message box saying "Your Smartphone has connected". OK Next Check the "Serial port" checkbox. Done Done Menu/COM Ports Select your GPS. Menu/New Outgoing Port. Select your device and press Select. You will see a COM port that has been chosen for your GPS. For example, COM6. Done Done Done Now your GPS is set up on COM6. Start your GPS app and configure it to use COM6.
For Smartphone (Windows Mobile Standard 6):
- Make sure Bluetooth is set to "On".
- You may have to press the pairing button on the GPS (if it has one).
- Start/Settings/Connections/Bluetooth.
- Pick Bluetooth again.
Add new Device... (it will then search for Bluetooth devices) - Select your GPS device from the list and press Next.
- The GPS you are trying to use should show up in the list.
- Select it. Press Next.
- Enter the passkey for the Bluetooth GPS. For example, 0000 or 0183
- Next
- You should get a message box saying "Your Smartphone has connected with XXXX".
- OK
- Enter a display name for the device. Enter a name and press Next.
- Check the "Serial port" checkbox.
- Done
- Done
- Start/Settings/Connections/Bluetooth.
Pick Bluetooth again. - Menu/COM Ports
- It will say "To add a COM port, select from one of the options under Menu."
- Press Menu.
- Select New Outgoing Port.
- Select the GPS you just added from the list.
- Pick the Com port you want to use (mine usually givex COM6 and COM7)
- You should then uncheck Secure Connection (unless you know you GPS will work with it on).
- Done.
For Smartphone (Windows Mobile Smartphone 5.0):
from http://blogs.msdn.com/windowsmobile/archive/2006/06/07/620387.aspx
Subscribe to:
Posts (Atom)