复选框状态保存在文本文件vb.net中
这是我的代码:复选框状态保存在文本文件vb.net中,vb.net,checkbox,text-files,Vb.net,Checkbox,Text Files,这是我的代码: Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged Dim checkboxvalue As String = File.ReadAllText(Application.StartupPath + "\discordstatus.txt") If checkboxvalue = "1" Then
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
Dim checkboxvalue As String = File.ReadAllText(Application.StartupPath + "\discordstatus.txt")
If checkboxvalue = "1" Then
CheckBox1.Checked = True
End If
If checkboxvalue = "0" Then
CheckBox1.Checked = False
End If
If CheckBox1.Checked = "1" Then
Dim fileReader As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath + "\discordstatus.txt").Replace("0", "1")
My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\discordstatus.txt", fileReader, False)
End If
If CheckBox1.Checked = "0" Then
Dim fileReader As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath + "\discordstatus.txt").Replace("1", "0")
My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\discordstatus.txt", fileReader, False)
End If
End Sub
我希望它(未选中时)将0放入文本文件,并(选中时)将1放入文本文件,此代码允许我通过手动更改文件中的数字来控制状态,但我无法选中或取消选中复选框,请帮助。您可以自动执行此操作
复选框的值将自动保存并为您设置。无代码。您似乎在等待用户单击复选框,然后从文件中读取值并设置复选框值,然后立即测试复选框值并将其写回文件。你的逻辑似乎有点混乱。我原以为从文件中加载值并设置复选框值的位会在窗体首次加载时出现,而不是在用户单击时出现。是否希望在用户单击时立即重新启动程序?我能问一下为什么吗?听起来很不寻常。