您必须自己定义它这是我编写的用于制作自定义密码输入框的代码我将其定义为一个类,然后继承表单类并为其赋予自定义属性通过这样做我创建了一个属性,该属性确定是否授予访问权限或不。您可以创建加密并与数据库通信以检索密码,但这仅显示了如何使用自定义控件。
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