简体   繁体   English

如何在文本框起始值中添加*并在C#中打印到标签中

[英]How To add * in Textbox Starting value and print into label in C#

I have some text boxes in my form where the user need to enter the different prices of article, what I want to do is to automatically add Starting value * whenever text is changed . 我在表单中有一些text boxes ,用户需要输入不同的商品价格,我想要做的就是每当文本更改时自动添加起始值* So when the user types 1 it is displayed like *****1 and text box Length are 6 size fix. 因此,当用户键入1它会像*****1一样显示,并且文本框“ Length”是6大小固定值。 then again user type 111 it is display like ***111 然后再次用户输入111它显示像***111

Not sure if you are on web, forms or what, but here is what you looking for: 不知道您是在上网,在表格上还是在网上,但是这是您要寻找的内容:

txt1.Text = txt1.Text.PadLeft(6, '*');

Reference: PadLeft 参考: PadLeft

You can use the PadLeft method for a string: 您可以对字符串使用PadLeft方法:

textBox1.Text = textBox1.Text.PadLeft(6, '*');

See an example here: https://dotnetfiddle.net/GPfFsx 在此处查看示例: https//dotnetfiddle.net/GPfFsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM