如何使用C#中的新值检测和替换文本框中输入的值? [英] how to detect and replace a value entered in the text box with a new value in C#?

查看:419
本文介绍了如何使用C#中的新值检测和替换文本框中输入的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个接受数字和小数值的文本框。



so现在当用户选择文本框中的全部或部分文本并尝试用新值替换我该怎么办?



请提供一个示例代码作为C#的新手?

Hi,

I have a text box which accepts numeric and decimal values.

so now when the user selects the entire or part of the of the text in the text box and try to replace with a new value how can i do it?

please provide a sample code as am new to C#?

推荐答案

只需处理TextChanged事件 - 当文本发生任何变化时即使它们替换了整个批次也能得到它。
Just handle the TextChanged event - you get it when any change happens to the text, even if they replace the whole lot.


您好,



一些有用的文本框控件属性,方法和事件:

事件:

1. TextChanged - 当Text属性的内容被更改时引发

属性:

1. TextBox.SelectedText - 允许您获取或设置当前选定的文本

2. TextBox.SelectionStart - 获取或设置第一个选定字符的索引(从0开始) )。

3. TextBox.SelectionLength - 获取或设置s的长度当选文本



方法:

1. TextBox.Select(开始,长度) - 允许您选择文本来自开始索引(从0开始),给定长度

2. TextBox.SelectAll() - 选择所有文字
Hi,

Some useful textbox control properties, methods and events:
Events:
1. TextChanged - Raised when content of Text property was changed
Properties:
1. TextBox.SelectedText - Allows you to get or set currently selected text
2. TextBox.SelectionStart - Gets or sets index of first selected character (0-based).
3. TextBox.SelectionLength - Gets or sets length of selected text

Methods:
1. TextBox.Select(start, length) - Allows you to select text from start index (0-based) with given length
2. TextBox.SelectAll() - Selects all text


查看我过去的答案:

如果我以rar格式发送我的项目源代码,任何人都可以发送代码进行查找和替换 [ ^ ]



-KR
See my past answer:
Can anyone send me the code for find and replace if I send my Projects Source code in rar format[^]

-KR


这篇关于如何使用C#中的新值检测和替换文本框中输入的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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