Home > Archive > Smartphone Developer Forum > January 2006 > Numeric TEXTBOX - How To (SmartPhone)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Numeric TEXTBOX - How To (SmartPhone)
|
|
| Alessandro Rozendo 2006-01-13, 7:04 pm |
| I am trying to set a Textbox to accept only numbers. The function I already
found.:
Edit_SetInputMode(Hwnd, EIM_NUMBERS)
but I am a newbie in VB and don't know where to put the reference to header
file (winuserm.h) im my code. For this reason I have the error code
BC30451: Name 'Edit_SetInputMode' is not declared.
Thanks for all help and sorry for my poor english
Alessandro Rozendo - Brazil
| |
|
| Add a new class in your project and copy this code.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class InputMode
{
#region "DllImports"
[DllImport("coredll.dll", EntryPoint="GetCapture")]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint="GetWindow")]
private static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
[DllImport("coredll.dll", EntryPoint="SendMessage")]
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint
wParam, uint lParam);
#endregion
const int GW_CHILD = 5;
const uint EM_SETINPUTMODE = 0x00DE;
/// <summary>
/// Set Control Input Mode
/// </summary>
/// <param name="ctrl">Control</param>
/// <param name="mode">InputMode</param>
public static void SetInputMode(Control ctrl, inputMode mode)
{
ctrl.Capture = true;
IntPtr h = GetCapture();
ctrl.Capture = false;
IntPtr hEditbox = GetWindow(h, GW_CHILD);
SendMessage(hEditbox, EM_SETINPUTMODE, 0, (uint)mode);
}
/// <summary>
/// InputModes
/// </summary>
public enum inputMode
{
Spell = 0,
T9 = 1,
Numbers = 2,
Text = 3
}
}
|
|
|
|
|