Cout编号在文本框中的书面信件 [英] Cout numbers of written letters in textbox

查看:86
本文介绍了Cout编号在文本框中的书面信件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有desctop应用程序,我有一些文本框,我必须在其中写一些单词,点击按钮后会发生一些事情。是否有一些方法我可以找到,用户在单击按钮之前写入文本框的字母数?例如,他必须写hallo并写halo,然后删除o并重写lo然后单击按钮。所以他写了hallo,但我想要一些可以计算的方法,他总共写了6个字母而不是5个文本框。 Ty for Answer。

Hallo, I have desctop application, i have some textbox and i must write some word in it and after click button something happen. Is there some method were i can find out, how many letters user write to textbox before he click button? For example he must write "hallo" and he write "halo", then he delete "o" and rewrite "lo" and then click button. So he write "hallo" but I want some method that will count, that he write totally 6 letters and dont 5 as is at textbox. Ty for Answer.

推荐答案

没有什么标准要做 - 我们通常不会对 如何 用户输入数据,但 他最终得到了什么。



你可以做到:处理TextBox的KeyPress事件并计算按键次数:

There is nothing standard to do that - we aren't generally interested in how a user entered the data, but what he ended up with.

You can do it: handle the KeyPress event for the TextBox and count the key presses:
private int pressed = 0;
private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (char.IsLetterOrDigit(e.KeyChar))
        {
        pressed++;
        }
    }


我认为它是一个WinForms应用程序,因为你说桌面应用程序。所以有一些事件你可以使用KeyUp,KeyDown或KeyPress。



你可以使用KeyDown事件并定义一个全局或静态变量来保存它输入的次数按下该单击按钮之前的那个事件。



KeyDown事件MSDN [ ^ ]



祝你好运,

OI
I think it is a WinForms application since you say desktop app. So there are some events that you can use KeyUp, KeyDown or KeyPress.

You can use KeyDown event and define a global or static variable that holds how many times it enters that event before that click button is pressed.

KeyDown Event MSDN[^]

Good luck,
OI


这篇关于Cout编号在文本框中的书面信件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆