Smartphone Number Entry

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

This has probably been asked before (I can't imagine anyone never
needing one of these) but I haven't found any good info on it yet...

Basically I need an input box that only accepts numbers. So when the
user hits the 2 key on the phone it will input a '2' character into
the box instead of the normal multi-tap 'a'/'b'/'c'/'2' characters. I
imagine that the 1 key could possibly enter a '.' character. In any
case, I am surprised that there isn't a property of TextBox to do
this. Does anyone know if this functionality exists in the .NET
Compact Framework but is buried? Or is there a popular custom control
(free preferably) that does it? I'd like to avoid writing my own
control to do it though I suppose that it is a last resort...

-Mike-
 
Hi,
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case e.KeyChar
Case ".", ",", "?", "!", "-", "'", "@", ":", "1"
TextBox1.SelectedText = "1"
e.Handled = True

would work (albeit not the best solution), but there may be an API to switch
to numbers, letters, T9 etc

Pete
 
That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-
 
Hi,
i just changed the getcapture to getfocus and it worked fine - i have a
working sample if you need it


Pete
--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
sorry - just found the best way -
http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com
 
Could you show me some code? I tried making the change myself and
still have no luck. Thanks for all your help.

-Mike-

Pete Vickers said:
Hi,
i just changed the getcapture to getfocus and it worked fine - i have a
working sample if you need it


Pete
--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
sorry - just found the best way -
http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

This has probably been asked before (I can't imagine anyone never
needing one of these) but I haven't found any good info on it yet...

Basically I need an input box that only accepts numbers. So when the
user hits the 2 key on the phone it will input a '2' character into
the box instead of the normal multi-tap 'a'/'b'/'c'/'2' characters. I
imagine that the 1 key could possibly enter a '.' character. In any
case, I am surprised that there isn't a property of TextBox to do
this. Does anyone know if this functionality exists in the .NET
Compact Framework but is buried? Or is there a popular custom control
(free preferably) that does it? I'd like to avoid writing my own
control to do it though I suppose that it is a last resort...

-Mike-
 
Hi,
this is the code that works for me, slightly changed from the original

Thanks

Pete
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu


Enum InputMode As Integer
IM_SPELL = &H0
IM_AMBIG = &H1
IM_NUMBERS = &H2
End Enum

<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetCapture() As IntPtr

End Function
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetFocus() As IntPtr
End Function

Sub SetInputMode(ByVal InputMode As InputMode, ByVal Control As
Windows.Forms.Control)

Const EM_SETINPUTMODE As Integer = &HDE

Dim wparam As New IntPtr(0)
Dim lparam As New IntPtr(InputMode)
Dim msg As New Microsoft.WindowsCE.Forms.Message
Dim container As New Microsoft.WindowsCE.Forms.MessageWindow

Control.Capture = True
'Dim hWnd As IntPtr = GetCapture()
Dim hWnd As IntPtr = GetFocus()
Control.Capture = False

msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd,
EM_SETINPUTMODE, wparam, lparam)
container.PostMessage(msg)

End Sub



#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.TextBox1 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 40)
Me.TextBox1.Size = New System.Drawing.Size(142, 25)
Me.TextBox1.Text = ""
'
'Form1
'
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"

End Sub

#End Region


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SetInputMode(InputMode.IM_NUMBERS, TextBox1)
End Sub
End Class

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
Could you show me some code? I tried making the change myself and
still have no luck. Thanks for all your help.

-Mike-

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i just changed the getcapture to getfocus and it worked fine - i have a
working sample if you need it


Pete
--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in
message
Hi,
sorry - just found the best way -
http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search
Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

This has probably been asked before (I can't imagine anyone never
needing one of these) but I haven't found any good info on it yet...

Basically I need an input box that only accepts numbers. So when the
user hits the 2 key on the phone it will input a '2' character into
the box instead of the normal multi-tap 'a'/'b'/'c'/'2' characters. I
imagine that the 1 key could possibly enter a '.' character. In any
case, I am surprised that there isn't a property of TextBox to do
this. Does anyone know if this functionality exists in the .NET
Compact Framework but is buried? Or is there a popular custom control
(free preferably) that does it? I'd like to avoid writing my own
control to do it though I suppose that it is a last resort...

-Mike-
 
Again, Pete, thanks for all your help and patience. I converted this
code to C# (I'm using that language to develop my app) which shouldn't
be any problem thanks to the nature of .NET, right? Anyway, the one
line of code that gives me problems is the line:

container.PostMessage(msg)

According to VS.NET 2003 PostMessage is a static/Shared method of
Microsoft.WindowsCE.Forms.MessageWindow. So I have to replace the line
with:

Microsoft.WindowsCE.Forms.MessageWindow.PostMessage(ref msg); // C#
version

Could this be my problem? How does your line work as written? Does the
VB.NET library have PostMessage as a non-Shared method? I thought all
..NET languages used the same library?

Another possibility: I am testing this on the Smartphone 2003
emulator. Could it be that this emulator doesn't handle numeric input
properly but this code would work fine on a real phone?

-Mike-

Pete Vickers said:
Hi,
this is the code that works for me, slightly changed from the original

Thanks

Pete
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu


Enum InputMode As Integer
IM_SPELL = &H0
IM_AMBIG = &H1
IM_NUMBERS = &H2
End Enum

<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetCapture() As IntPtr

End Function
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetFocus() As IntPtr
End Function

Sub SetInputMode(ByVal InputMode As InputMode, ByVal Control As
Windows.Forms.Control)

Const EM_SETINPUTMODE As Integer = &HDE

Dim wparam As New IntPtr(0)
Dim lparam As New IntPtr(InputMode)
Dim msg As New Microsoft.WindowsCE.Forms.Message
Dim container As New Microsoft.WindowsCE.Forms.MessageWindow

Control.Capture = True
'Dim hWnd As IntPtr = GetCapture()
Dim hWnd As IntPtr = GetFocus()
Control.Capture = False

msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd,
EM_SETINPUTMODE, wparam, lparam)
container.PostMessage(msg)

End Sub



#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.TextBox1 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 40)
Me.TextBox1.Size = New System.Drawing.Size(142, 25)
Me.TextBox1.Text = ""
'
'Form1
'
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"

End Sub

#End Region


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SetInputMode(InputMode.IM_NUMBERS, TextBox1)
End Sub
End Class

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
Could you show me some code? I tried making the change myself and
still have no luck. Thanks for all your help.

-Mike-

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
i just changed the getcapture to getfocus and it worked fine - i have a
working sample if you need it


Pete
--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in
message
Hi,
sorry - just found the best way -

http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

This has probably been asked before (I can't imagine anyone never
needing one of these) but I haven't found any good info on it yet...

Basically I need an input box that only accepts numbers. So when the
user hits the 2 key on the phone it will input a '2' character into
the box instead of the normal multi-tap 'a'/'b'/'c'/'2' characters. I
imagine that the 1 key could possibly enter a '.' character. In any
case, I am surprised that there isn't a property of TextBox to do
this. Does anyone know if this functionality exists in the .NET
Compact Framework but is buried? Or is there a popular custom control
(free preferably) that does it? I'd like to avoid writing my own
control to do it though I suppose that it is a last resort...

-Mike-
 
Hi,
I tested it on the 2003 emulator and it worked fine - did the sample work as
supplied in VB?
Apart from that - sorry, I don't know. There are some threads on this on
www.modaco.com

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
Again, Pete, thanks for all your help and patience. I converted this
code to C# (I'm using that language to develop my app) which shouldn't
be any problem thanks to the nature of .NET, right? Anyway, the one
line of code that gives me problems is the line:

container.PostMessage(msg)

According to VS.NET 2003 PostMessage is a static/Shared method of
Microsoft.WindowsCE.Forms.MessageWindow. So I have to replace the line
with:

Microsoft.WindowsCE.Forms.MessageWindow.PostMessage(ref msg); // C#
version

Could this be my problem? How does your line work as written? Does the
VB.NET library have PostMessage as a non-Shared method? I thought all
.NET languages used the same library?

Another possibility: I am testing this on the Smartphone 2003
emulator. Could it be that this emulator doesn't handle numeric input
properly but this code would work fine on a real phone?

-Mike-

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in message
Hi,
this is the code that works for me, slightly changed from the original

Thanks

Pete
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu


Enum InputMode As Integer
IM_SPELL = &H0
IM_AMBIG = &H1
IM_NUMBERS = &H2
End Enum

<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetCapture() As IntPtr

End Function
<System.Runtime.InteropServices.DllImport("coredll.dll")> _
Public Shared Function GetFocus() As IntPtr
End Function

Sub SetInputMode(ByVal InputMode As InputMode, ByVal Control As
Windows.Forms.Control)

Const EM_SETINPUTMODE As Integer = &HDE

Dim wparam As New IntPtr(0)
Dim lparam As New IntPtr(InputMode)
Dim msg As New Microsoft.WindowsCE.Forms.Message
Dim container As New Microsoft.WindowsCE.Forms.MessageWindow

Control.Capture = True
'Dim hWnd As IntPtr = GetCapture()
Dim hWnd As IntPtr = GetFocus()
Control.Capture = False

msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd,
EM_SETINPUTMODE, wparam, lparam)
container.PostMessage(msg)

End Sub



#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.TextBox1 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 40)
Me.TextBox1.Size = New System.Drawing.Size(142, 25)
Me.TextBox1.Text = ""
'
'Form1
'
Me.Controls.Add(Me.TextBox1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"

End Sub

#End Region


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
SetInputMode(InputMode.IM_NUMBERS, TextBox1)
End Sub
End Class

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

Mike said:
Could you show me some code? I tried making the change myself and
still have no luck. Thanks for all your help.

-Mike-

"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in
message
Hi,
i just changed the getcapture to getfocus and it worked fine - i have a
working sample if you need it


Pete
--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

That code doesn't seem to work.

One weird thing is that the line:

container.PostMessage(msg)

produces a syntax error because PostMessage is a static/Shared method
of Microsoft.WindowsCE.Forms.MessageWindow. So I replaced the instance
reference "container" with a static call and the text controls still
insist on multi-tap input instead of numeric.

-Mike-


"Pete Vickers [eMVP]" <pete at gui - innovations dot com> wrote in
message
Hi,
sorry - just found the best way -
http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search
Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com

This has probably been asked before (I can't imagine anyone never
needing one of these) but I haven't found any good info on it yet...

Basically I need an input box that only accepts numbers. So
when
the
user hits the 2 key on the phone it will input a '2' character into
the box instead of the normal multi-tap 'a'/'b'/'c'/'2' characters. I
imagine that the 1 key could possibly enter a '.' character.
In
any
case, I am surprised that there isn't a property of TextBox to do
this. Does anyone know if this functionality exists in the ..NET
Compact Framework but is buried? Or is there a popular custom control
(free preferably) that does it? I'd like to avoid writing my own
control to do it though I suppose that it is a last resort...

-Mike-
 
Thanks for all your help, Pete. I tried your code out in VB.NET and it
works perfectly. If anyone out there knows how to convert this into C#
please let me know. The weird part is that in VB this is legal:

Dim container As New Microsoft.WindowsCE.Forms.MessageWindow

'... code here ...

container.PostMessage(msg)


but when I translate it to C# as:

Microsoft.WindowsCE.Forms.MessageWindow container = new
Microsoft.WindowsCE.Forms.MessageWindow();

// ... code here ...

container.PostMessage(ref msg);


it does not compile! It gives the following error:

Static member 'Microsoft.WindowsCE.Forms.MessageWindow.PostMessage(ref
Microsoft.WindowsCE.Forms.Message)' cannot be accessed with an
instance reference; qualify it with a type name instead

meaning that I have to write it as:

Microsoft.WindowsCE.Forms.MessageWindow.PostMessage(ref msg);

which doesn't appear to work correctly when the app is run. Why is it
that a Shared method in VB can be called with the instance variable
name but a static method in C# cannot? How do I make the call
equivelent to the VB example?

-Mike-
 
Back
Top