[Windows Mobile]設定 TextBox 的輸入法狀態

  • 9762
  • 0
  • 2013-04-15

[Windows Mobile]設定 TextBox 的輸入法狀態

 

1. 問題描述

在 Windows Forms 應用程式中,可透過 TextBox.ImeMode 屬性設定輸入法狀態,如下圖所示。

在智慧型裝置程式中,如何設定 TextBox 的輸入法狀態?

 

image

 

2. 方法

在智慧型裝置程式中,需透過 InputModeEditor.SetInputMode 方法 : 指定 Smartphone 上的輸入模式。

使用前,必須先將 Microsoft.WindowsCE.Forms 加入參考,位置在 C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies

image image

接著在程式碼中 using

using Microsoft.WindowsCE.Forms;

 

 

以下程式碼將 TextBox 指定輸入模式為 InputMode.Numeric (只接受數字字元與符號)

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.WindowsCE.Forms;

namespace SmartDeviceProject2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // 指定 Smartphone 上的輸入模式為 InputMode.Numeric (只接受數字字元與符號)
            InputModeEditor.SetInputMode(textBox1, InputMode.Numeric);
        }
    }
}

 

 

可設定的 InputMode 輸入模式請參考 InputMode 列舉型別

image

 

3. 參考

how do i set input mode of textbox?