你必須定義它自己,這是我寫的做一個自定義的密碼輸入框代碼中,我把它定義爲一個類,然後繼承表單類並給它定製屬性通過這樣做,我創建了一個屬性來確定訪問是否被授予。您可以創建加密並與數據庫進行通信以進行密碼檢索,但這只是簡單地展示瞭如何使用自定義控件。
Public Class Form1
Dim test As New CustomForm("workflow")
Public Class CustomForm
Inherits Form
Property SecretPassword As String
Property GrantAccess As Boolean
Sub New(Password As String)
GrantAccess = False
Me.SecretPassword = Password
Dim lbl As New Label
lbl.Text = "Password"
Me.Controls.Add(lbl)
Me.Text = "***PASSWORD INPUT REQUIRED***"
Dim frmSZ As New Size(400, 100)
Me.Size = frmSZ
Dim IBox As New TextBox
AddHandler IBox.KeyDown, AddressOf TextBox1_KeyDown
Dim ibox20 As New Point(100, 0)
IBox.Location = ibox20
IBox.PasswordChar = "*"
Me.Controls.Add(IBox)
Me.Show()
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.KeyCode.Enter Then
Try
Dim passswordInput As String = sender.text
If passswordInput = Me.SecretPassword Then
GrantAccess = True
Me.Dispose()
Else
MsgBox("Sorry the password you entered is not correct please try again. The password is case sensitive make sure your caps lock is not on.")
End If
Catch ex As Exception
End Try
End If
End Sub
End Class
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(test.GrantAccess)
End Sub
End Class
如果這是WinForms,請不要使用InputBox。使用TextBox創建表單並設置密碼字符屬性。 – LarsTech
正確。您不能使用帶有密碼字符的InputBox。 –