我有以下代码:
Imports System.Web.Security
Public Class Form1
Dim symbols As Integer = 0
Private Sub cbSymbols_CheckedChanged(sender As Object, e As EventArgs) Handles cbSymbols.CheckedChanged
If cbSymbols.CheckState = 1 Then
symbols = 1
ElseIf cbSymbols.CheckState = 0 Then
symbols = 0
End If
End Sub
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim password As String = Membership.GeneratePassword(ComboBox1.SelectedIndex + 6, symbols)
Label1.Text = password
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Font = New Font("Arial", 14)
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
End Sub
End Class
但是,无论我的复选框 (cbSymbols) 是否被选中,我的密码在勾选时都有 1 个符号,而未勾选时有 2 个符号。任何人都可以帮我诊断这个问题和/或改进我的代码吗?谢谢。