简体   繁体   English

如何将文本框内容保存到应用程序本身?

[英]How can I save the textbox content to the application itself?

Simply put, for example, I want to save content of a textbox to the application itself.简单地说,例如,我想将文本框的内容保存到应用程序本身。

I tried "My.Settings" but type of settings must be "user-scoped" & settings(string content of textbox) extracting to %appdata% folder(user.config).我尝试了“My.Settings”,但设置类型必须是“用户范围”和设置(文本框的字符串内容)提取到 %appdata% 文件夹(user.config)。

I want store the data(confidential text) on the application without extracting it to anywhere.我想将数据(机密文本)存储在应用程序上,而不将其提取到任何地方。

On the other hand "application-scoped" settings are "Read-Only" and values of settings can not be change while type of settings "application-scoped".另一方面,“应用程序范围”的设置是“只读”的,设置的值不能更改,而设置类型为“应用程序范围”。 I want settings(string content of textbox) always changeable by the user of app.我希望应用程序的用户始终可以更改设置(文本框的字符串内容)。

TextFile in Resources is also read-only...I have to extract TextFile for changing the content of TextFile.资源中的 TextFile 也是只读的...我必须提取 TextFile 以更改 TextFile 的内容。

How can i do that?我怎样才能做到这一点?

You can use My.Computer.Filesystem.WriteAllText() & My.Computer.Filesystem.ReadAllText() to write/read files.您可以使用My.Computer.Filesystem.WriteAllText()My.Computer.Filesystem.ReadAllText()来写入/读取文件。 And there's no better way.而且没有更好的办法。

But yeah, you can achieve your requirement by saving the data into Registry, ie if you want to save your any text data which is accessible anywhere from the device, it could really be helpful.但是,是的,您可以通过将数据保存到注册表来满足您的要求,即,如果您想保存可从设备的任何位置访问的任何文本数据,这真的很有帮助。

Note that your application will require to be ran as administrator for saving/reading registry values.请注意,您的应用程序需要以管理员身份运行才能保存/读取注册表值。

To save registry value:保存注册表值:

My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\something", "ValueName", "Value")

To access it:要访问它:

My.Computer.Registry.GetValue("Same Location", "Same ValueName", Nothing) ' Note that "Nothing" is returned when value doesn't exists.

Hope it helps.希望能帮助到你。

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

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