C#Windows窗体保存输入? [英] C# Windows Form Save Input?

查看:108
本文介绍了C#Windows窗体保存输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows窗体(C#)中,如何使程序将用户输入的数据保存到文本框中?



如果我在文本框中输入stuff这个词,当我重新打开程序时,如何加载程序?



谢谢。

解决方案

  1. http://msdn.microsoft.com/en-us/library/a19tt6sk(v=vs.110).aspx [ ^ ];
  2. http:/ /msdn.microsoft.com/en-us/library/ms143375%28v=vs.110%29.aspx [ ^ ];
  3. 利润! : - )





祝你好运,

-SA

有很多方法可以做到这一点,其中一些方法对于特定情况比另一种更好。在不了解您的全部要求的情况下,实际上不可能给出做到这一点 - 这是最好的方式的答案,因为对于一个应用来说非常好的解决方案对另一个应用来说是非常糟糕的解决方案。



例如,您想要做的就是保存一个字符串,然后使用Settings.settings文件可能是最好的。但是如果以后你想要存储几十行混合文本和数字,那么它就会非常糟糕,你可以用数据库,CSV文件或XML解决方案做得更好。



假设它是单个值:

在解决方案资源管理器窗格中打开您的项目,然后打开属性分支。

双击 Settings.settingsleaf,并添加一个新名称MyValue,输入String,将值留空,或者给它一个默认值。

保存并关闭页面。

在您的代码中,您可以阅读以下值:

  string  my  value  = Properties.Settings.Default.MyValue; 

并保存:

属性。 Settings.Default.MyValue = newStringValue; 
Properties.Settings.Default.Save();


In a Windows Form (C#), how would you make your program save the data which the user enters into a text box?

If I enter the word "stuff" into a text box, how would I make the program load that when I reopen the program?

Thanks.

解决方案

  1. http://msdn.microsoft.com/en-us/library/a19tt6sk(v=vs.110).aspx[^];
  2. http://msdn.microsoft.com/en-us/library/ms143375%28v=vs.110%29.aspx[^];
  3. PROFIT! :-)



Good luck,

—SA


There are a huge number of ways to do this, some of which are better for a given situation than another. Without knowing your full requirement, it isn't really possible to give a "do this - it's the best way" answer, as what is very good for one application is a very poor solution for another.

For example, of all you ever want to do is save a single string, then using the Settings.settings file is probably the best. But if later you want to store a couple of dozen rows of mixed text and numbers then it is very poor and you'd be much better off with a database, or CSV file, or XML solution.

Assuming it is a single value:
Open your project in the Solution explorer pane, and open the Properties branch.
Double click the "Settings.settings" leaf, and add a new name "MyValue", type "String", leave the Value blank, or give it a default value.
Save and close the page.
In your code, you can read the value:

string my value = Properties.Settings.Default.MyValue;

And save it with:

Properties.Settings.Default.MyValue = newStringValue;
Properties.Settings.Default.Save();


这篇关于C#Windows窗体保存输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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