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 the C # winform program reads the values in the text

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

How to read the value in the text of C # winform program, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

In the process of C#winform program development, we may need to set some changing values regularly, but these values are used for comparison or reference in the program. For example, we set a fixed value for the program to check whether the current value conforms to the regulations. This function is actually very simple. Next, let's take a look at the process of implementation.

Create a winform program and create a file with the suffix ini in the program's release or debug directory. We will read the values in this file later.

The file at the end of ini, which can be opened by double-click, similar to a text document. We create a unlock.ini file here and fill it with the characters TEST888.

To design the program interface, I am here to check whether the value entered in the textbox box is the same as the value I have already set in the INI file. Here I use a label control label2 to grab the set value, of course, this control is set to not display.

Write code:

Quote IO:using System.IO

This operation involves read and write access to the file, so you must first reference the IO.

Write code:

Write a function that reads the unlock.ini file we built earlier, that is, the winform interface reads this value and assigns it to the label2 we created.

Private void readunlock () {try {StreamReader reader1 = new StreamReader ("unlock.ini"); label2.Text = reader1.ReadLine (); reader1.Close ();} catch (Exception ex) {throw ex;}}

Write code:

Call the readunlock () function to read the value when the interface is loaded.

Private void Warn_Load (object sender, EventArgs e) {readunlock ();}

Write code:

Write the enter event of the textbox box to check whether the entered value is the same as the value that was originally saved in the unlock.ini file.

Private void textBox1_KeyDown (object sender, KeyEventArgs e) {if ((e.KeyCode = = Keys.Enter) & & (textBox1.Text = = label2.Text)) {this.DialogResult = DialogResult.OK; this.Close ();}

The line program checks the results, and after we enter the correct value, the interface window closes and achieves what we want to achieve.

This is the answer to the question about how the C # winform program reads the values in the text. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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