【问题标题】:Textbox is not writing the first letter every time I open the appliction每次打开应用程序时,文本框都不写第一个字母
【发布时间】:2019-10-12 01:36:48
【问题描述】:

我在一个 c# windows 窗体应用程序中调整了一些文本框,例如,将每个字母变为大写,或禁用特殊字符等。

但是每次我打开这个应用程序并尝试在其中一个文本框中写一些东西时,第一个字母都不会出现,就好像我从来没有写过任何东西一样。之后就可以正常使用了(条件全)。

private void TxbDGVFilter_KeyPress(object sender, KeyPressEventArgs e)
        {
            txbDGVFilter.CharacterCasing = CharacterCasing.Upper;
            if (!(char.IsNumber(e.KeyChar)) && !(Char.IsLetter(e.KeyChar)) && (e.KeyChar != (char)Keys.Back))
            {
                MessageBox.Show("No special characters allowed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                e.Handled = true;
                return;
            }
        }

【问题讨论】:

  • 尝试 keydown 事件
  • 尝试改用KeyUp 事件。
  • 你应该处理 Key Press 的 Key Down 事件
  • 我尝试了 KeyDown 事件,但结果相同。

标签: c# textbox


【解决方案1】:
txbDGVFilter.CharacterCasing = CharacterCasing.Upper;

这段代码应该在构造函数中运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 2021-07-05
    • 1970-01-01
    • 2021-03-07
    • 2020-09-03
    相关资源
    最近更新 更多