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);

          }

 

      }

目录
相关文章
Failed to execute ‘setAttribute‘ on ‘Element‘: ‘;min-height:‘ is not a valid attribute name.添加100vh
Failed to execute ‘setAttribute‘ on ‘Element‘: ‘;min-height:‘ is not a valid attribute name.添加100vh
|
5月前
|
Android开发
解决RenderUiKitView object was given an infinite size during layout.
解决RenderUiKitView object was given an infinite size during layout.
49 3
|
8月前
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
62 6
|
8月前
|
前端开发
line-height与height的区别
line-height与height的区别
82 0
究竟什么时候使用line-height合适------line-height的实际应用
1) 单行文字的垂直居中对齐 把line-height值设置为height一样大小的值可以实现单行文字的垂直居中。这句话确实是正确的,但其实也是有问题的。问题在于height,把line-height设置为您需要的box的大小可以实现单行文字的垂直居中,height是多余的。
47 0
flag_in_your_hand
flag_in_your_hand
55 0
Latex "Error: Extra alignment tab has been changed to \cr. "
Latex 编译时出现 Error: Extra alignment tab has been changed to \cr.  是因为\begin{tabular}后面的参数指定为7列,而实际排了8列数据。
4248 0