csharp:datagridview enter Half Width and Full Width characters

简介: /// <summary> /// 全角 /// </summary> /// <param name="unicodeString"></param> /// <returns></returns> public static string F
  /// <summary>

      /// 全角

      /// </summary>

      /// <param name="unicodeString"></param>

      /// <returns></returns>

      public static string FullWidthConvertor(string unicodeString)

      {

 

          StringBuilder sb = new StringBuilder(256);

          LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_FULLWIDTH, unicodeString, -1, sb, sb.Capacity);

          return sb.ToString();

 

      }

      /// <summary>

      /// 半角

      /// </summary>

      /// <param name="unicodeString"></param>

      /// <returns></returns>

      public static string HalfWidthConvertor(string unicodeString)

      {

 

          StringBuilder sb = new StringBuilder(256);

          LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_HALFWIDTH, unicodeString, -1, sb, sb.Capacity);

          return sb.ToString();

 

 

      }

      private const uint LCMAP_FULLWIDTH = 0x00800000;

      private const uint LOCALE_SYSTEM_DEFAULT = 0x0800;

      private const uint LCMAP_HALFWIDTH = 0x00400000;

 

      [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]

      public static extern int LCMapString(uint Locale, uint dwMapFlags, string lpSrcStr, int cchSrc, StringBuilder lpDestStr, int cchDest);

 

 

 

/// <summary>

      /// DataGridView单位格输入全角转半角

      /// </summary>

      /// <param name="sender"></param>

      /// <param name="e"></param>

      private void dridViewRowNumberNo_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

      {

          GridViewRowNumberNo dt = sender as GridViewRowNumberNo;

          //获取列序号

          int columnIndex = dt.CurrentCell.ColumnIndex;

          //单位格转化成文本框

          TextBox tb = e.Control as TextBox;

          //委托单位格KeyPress事务

          tb.KeyPress += new KeyPressEventHandler(geovindu_KeyPress);

      }

      /// <summary>

      /// 单位格KeyPress事务

      /// </summary>

      /// <param name="sender"></param>

      /// <param name="e"></param>

      private void geovindu_KeyPress(object sender, KeyPressEventArgs e)

      {

          Control ctl = sender as Control;

          if (ctl == null)

              return;

          if (ctl.ImeMode != ImeMode.Hangul)

              ctl.ImeMode = ImeMode.Hangul;

          //全角转半角

          if (e.KeyChar >= 65296 && e.KeyChar <= 65305)

          {

              e.KeyChar -= Convert.ToChar(65248);

          }

 

      }

目录
相关文章
|
4月前
flag_in_your_hand
flag_in_your_hand
24 0
|
4月前
|
前端开发
display:contents
display:contents
23 1
|
5月前
can't do nonzero end-relative seeks
can't do nonzero end-relative seeks
21 0
|
10月前
|
容器
An InputDecorator, which is typically created by a TextField, cannot have an unbounded width
An InputDecorator, which is typically created by a TextField, cannot have an unbounded width
|
11月前
|
编译器 Python
ValueError matplotlib display text must have all code points 128 or use Unicode strings
ValueError matplotlib display text must have all code points 128 or use Unicode strings
73 0
|
算法
PAT (Advanced Level) Practice - 1033 To Fill or Not to Fill(25 分)
PAT (Advanced Level) Practice - 1033 To Fill or Not to Fill(25 分)
69 0
|
Android开发 数据格式 JSON
android报错 Expected BEGIN_OBJECT but was STRING at line 1 column 39 path $
      我在使用retrofit和Gson配合时,出现了这个问题,疑惑中乱七八糟瞎搞了一个下午没有解决。期间怀疑Gson解析不能使用泛型(因为我的解析使用了泛型),后来又觉得可能是我的关键字正好是解析器的某个关键字导致的异常,也打算过自定义Gson的解析过程,其实这些都不是。         第二天才搞明白,真正的问题是我的数据结构有问题,或者说我的解析出现了问题。  
4007 0
why Participants tab in GM6 is hidden - by extension
Created by Wang, Jerry, last modified on May 20, 2015
80 0
why Participants tab in GM6 is hidden - by extension
the code place where the binding is converted to final value displayed in ui
the code place where the binding is converted to final value displayed in ui
the code place where the binding is converted to final value displayed in ui
SAP UI5 dialog style max-height
Created by Wang, Jerry, last modified on Apr 09, 2015
103 0
SAP UI5 dialog style max-height