Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use TextBox Control in C #

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use the TextBox control in C#, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

As we all know, in some special cases, we sometimes need to let users enter only numbers in the text box, so how do we achieve it? In fact, this function is simple. We judge the data entered by the user in the KeyPress event of the text box. The following editor implements this function by coding.

Private void txtMaths_KeyPress (object sender,KeyPressEventArgs e) {If (e.KeyChartered characters 8 & &! char.IsDigit (e.KeyChar)) {MessageBox.Show ("only enter adjectives", "prompt", MessageBoxButtons.OK,MessageBoxIcon.Infomation); e.Handledcharacters truth;}}

Isn't it easy to limit the ability of text boxes to "input" numbers? In fact, as long as you think seriously when you encounter a problem, the difficult problem will also become simple! Let's continue to share:

To display the car symbol in the C # TextBox control, you can use the Environment.NewLine property. The NewLine attribute represents a string of lines defined by the system environment. The main code is as follows:

Private void Form2_Load (object sender,EventArgs e) {This.textBox1.Multiline=true; This.textBox1.WordWrap=true; This.textBox1.ScrollBars=ScrollBars.Vertical; textBox1.Text= "1342265654554565" + Environment.NewLine+ "455888888888888";}

Execute the C # TextBox program code, whether the carriage return character is displayed in the control!

Thank you for reading this article carefully. I hope the article "how to use TextBox controls in C#" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report