.net cf 中 TextBox 输入时小写转大写

一个小小的功能,不注意就难倒我了,呵呵。

在.net framework中,要实现此功能,很简单:(可有如下两种)
1> 把 TextBox 的 CharacterCasing 设置为 "Upper"
2> 响应 TextBox 的 KeyPress 事件,代码如下:
    if (Char.IsLower(e.KeyChar))
                e.KeyChar = Char.ToUpper(e.KeyChar);

在.net compact framework中,这两种方式不行的。
1> .net cf中 TextBox 没有 CharactCasing 属性 (opennet cf应该是有的)
2> .net cf中 TextBox KeyPress 事件下的 e.KeyChar 为只读属性

So, 我实现如下:
响应 TextBox 的 KeyUp 事件,代码如下:
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {      
            textBox1.Text = textBox1.Text.ToUpper();
            textBox1.SelectionStart = textBox1.Text.Length;
            return;
        }

呵呵,不知各位有更好的实现没?

原文地址:https://www.cnblogs.com/answer/p/1435439.html