简体   繁体   English

如何在 VB .NET 应用程序中保存应用程序设置?

[英]How can I save application settings in a VB .NET application?

I made a projet a month ago in C# where I used application settings to save data.一个月前我在 C# 中做了一个项目,我使用应用程序设置来保存数据。 This time, I'm making a project in VB .NET where I need to store data.这一次,我正在 VB .NET 中创建一个项目,我需要在其中存储数据。 I have a textbox where the user input a certain key and if he gets it right, it sets a setting to true.我有一个文本框,用户在其中输入某个键,如果他输入正确,它会将设置设置为 true。 Here's the code.这是代码。

 Public Class Form4
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      If TextBox1.Text = ("CF4A438C1F68D" Or "7552B2C629D11" Or "9C9C94A73141A" Or "7EE3998DAB3D3" Or "FC4DABC9CA7EA" Or "FDEE4B1F2C113" Or "D773E97B47531" Or "AABBBF181D39A" Or "36F37B39D19A5") Then
          Properties.Settings.Default.ActivatedVersion = True
          Properties.Settings.Default.Save()
      End If
  End Sub
End Class

Unfortunately, when I write Properties, it doesn't work.不幸的是,当我编写属性时,它不起作用。 How can I do this?我怎样才能做到这一点?

In VB, you use My.Settings rather than Properties.Settings.Default .在 VB 中,您使用My.Settings而不是Properties.Settings.Default

Also, you don't necessarily need to call Save explicitly as it will happen automatically, by default, when the application exits.此外,您不一定需要显式调用Save ,因为默认情况下,当应用程序退出时,它会自动发生。 It won't happen if the application crashes but, if you have done the right thing and handled the UnhandledException event, the application will not crash, even if an unhandled exception is thrown.如果应用程序崩溃,则不会发生这种情况,但是,如果您做了正确的事情并处理了UnhandledException事件,则即使抛出未处理的异常,应用程序也不会崩溃。

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

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