【发布时间】:2018-05-18 00:23:24
【问题描述】:
这是我的代码:
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 放入文本文件中,此代码可让我通过手动更改文件中的数字来控制状态,但我无法检查或取消选中复选框,请帮助。
【问题讨论】:
-
您似乎在等待用户单击复选框,然后从文件中读取值并设置复选框值,然后立即测试复选框值并将其写回文件。你的逻辑似乎有点混乱。我本以为您从文件中加载值并设置复选框值会在您的表单首次加载时发生,而不是在用户单击时发生。
-
您希望程序在用户点击时立即重启?我能问为什么吗?听起来不寻常。
标签: vb.net checkbox text-files