这是我的代码:
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,此代码让我通过手动更改文件中的数字来控制状态,但是我无法检查或取消选中该复选框,请提供帮助。
答案 0 :(得分:1)
您可以自动执行此操作。
复选框的值将自动保存并为您设置。没有代码。