如何用VB撰寫數字鍵盤,用于密碼輸入的,求教
uj5u.com熱心網友回復:
建一個空表單,不用拉控制元件把代碼貼進去運行就行了
Private WithEvents Num0 As Label
Private WithEvents Num1 As Label
Private WithEvents Num2 As Label
Private WithEvents Num3 As Label
Private WithEvents Num4 As Label
Private WithEvents Num5 As Label
Private WithEvents Num6 As Label
Private WithEvents Num7 As Label
Private WithEvents Num8 As Label
Private WithEvents Num9 As Label
Private WithEvents Cancel As Label
Private WithEvents Enter As Label
Private WithEvents PassBox As TextBox
Private WithEvents Back As Label
Private Sub Form_Load()
Dim S() As Label
Dim I As Integer
ReDim S(12)
For I = 0 To UBound(S)
Set S(I) = Me.Controls.Add("VB.Label", "Label_" & I)
S(I).Move 60 + (I Mod 4) * 420, 480 + (I \ 4) * 420, 360, 360
S(I).Appearance = 0
S(I).BorderStyle = 1
S(I).Alignment = 2
S(I).Caption = CStr(I)
S(I).FontSize = 14
S(I).Visible = True
Next
S(10).Move 900, 1315, 780, 360
S(10).BackColor = vbYellow
S(10).Caption = "Back"
S(10).FontSize = 12
S(11).Move 60, 1720, 780, 360
S(11).BackColor = vbRed
S(11).Caption = "Cancel"
S(11).FontSize = 12
S(12).Move 900, 1720, 780, 360
S(12).BackColor = vbGreen
S(12).Caption = "Enter"
S(12).FontSize = 12
Set Num0 = S(0)
Set Num1 = S(1)
Set Num2 = S(2)
Set Num3 = S(3)
Set Num4 = S(4)
Set Num5 = S(5)
Set Num6 = S(6)
Set Num7 = S(7)
Set Num8 = S(8)
Set Num9 = S(9)
Set Back = S(10)
Set Cancel = S(11)
Set Enter = S(12)
Set PassBox = Me.Controls.Add("VB.TextBox", "PassBox_0")
PassBox.Move 60, 60, 1620, 360
PassBox.Appearance = 0
PassBox.BorderStyle = 1
PassBox.BackColor = vbBlack
PassBox.ForeColor = vbGreen
PassBox.FontSize = 16
PassBox.PasswordChar = "*"
PassBox.Visible = True
PassBox.Enabled = False
End Sub
Private Sub Num0_Click()
PassBox.Text = PassBox.Text & Num0.Caption
End Sub
Private Sub Num1_Click()
PassBox.Text = PassBox.Text & Num1.Caption
End Sub
Private Sub Num2_Click()
PassBox.Text = PassBox.Text & Num2.Caption
End Sub
Private Sub Num3_Click()
PassBox.Text = PassBox.Text & Num3.Caption
End Sub
Private Sub Num4_Click()
PassBox.Text = PassBox.Text & Num4.Caption
End Sub
Private Sub Num5_Click()
PassBox.Text = PassBox.Text & Num5.Caption
End Sub
Private Sub Num6_Click()
PassBox.Text = PassBox.Text & Num6.Caption
End Sub
Private Sub Num7_Click()
PassBox.Text = PassBox.Text & Num7.Caption
End Sub
Private Sub Num8_Click()
PassBox.Text = PassBox.Text & Num8.Caption
End Sub
Private Sub Num9_Click()
PassBox.Text = PassBox.Text & Num9.Caption
End Sub
Private Sub Back_Click()
PassBox.Text = Left(PassBox.Text, Len(PassBox.Text) - 1)
End Sub
Private Sub Cancel_Click()
PassBox.Text = ""
End Sub
Private Sub Enter_Click()
MsgBox "密碼結果=" & PassBox.Text, vbInformation + vbOKOnly, "密碼"
End Sub
uj5u.com熱心網友回復:
大哥,我要在觸摸屏上使用,輸入到文本檔案里面,能幫忙處理 下嗎?
uj5u.com熱心網友回復:
顯示按鍵:1、2、3、4、5、6、7、8、9、0、退格、確定,這幾個按鈕就行,能在觸摸屏上使用,把資訊輸入到文本檔案里面。
uj5u.com熱心網友回復:
自己建立一個表單,然后彈出這個視窗uj5u.com熱心網友回復:
狗尾續貂:Private WithEvents Num0 As Label
Private WithEvents Num1 As Label
Private WithEvents Num2 As Label
Private WithEvents Num3 As Label
Private WithEvents Num4 As Label
Private WithEvents Num5 As Label
Private WithEvents Num6 As Label
Private WithEvents Num7 As Label
Private WithEvents Num8 As Label
Private WithEvents Num9 As Label
Private WithEvents Cancel As Label
Private WithEvents Enter As Label
Private WithEvents PassBox As TextBox
Private WithEvents Back As Label
Private Order(0 To 9) As Integer
Private Sub Form_Load()
Dim S() As Label
Dim I As Integer
Dim a As Integer
Dim b As Integer
Dim t As Integer
ReDim S(12)
For I = 0 To 9
Order(I) = I
Next
Randomize
For I = 0 To 100
a = Int(Rnd * 10)
b = Int(Rnd * 10)
t = Order(a): Order(a) = Order(b): Order(b) = t
Next
For I = 0 To UBound(S)
Set S(I) = Me.Controls.Add("VB.Label", "Label_" & I)
S(I).Move 60 + (I Mod 4) * 420, 480 + (I \ 4) * 420, 360, 360
S(I).Appearance = 0
S(I).BorderStyle = 1
S(I).Alignment = 2
If I < 10 Then S(I).Caption = CStr(Order(I))
S(I).FontSize = 14
S(I).Visible = True
Next
S(10).Move 900, 1315, 780, 360
S(10).BackColor = vbYellow
S(10).Caption = "退格"
S(10).FontSize = 12
S(11).Move 60, 1720, 780, 360
S(11).BackColor = vbRed
S(11).Caption = "取消"
S(11).FontSize = 12
S(12).Move 900, 1720, 780, 360
S(12).BackColor = vbGreen
S(12).Caption = "確定"
S(12).FontSize = 12
Set Num0 = S(0)
Set Num1 = S(1)
Set Num2 = S(2)
Set Num3 = S(3)
Set Num4 = S(4)
Set Num5 = S(5)
Set Num6 = S(6)
Set Num7 = S(7)
Set Num8 = S(8)
Set Num9 = S(9)
Set Back = S(10)
Set Cancel = S(11)
Set Enter = S(12)
Set PassBox = Me.Controls.Add("VB.TextBox", "PassBox_0")
PassBox.Move 60, 60, 1620, 360
PassBox.Appearance = 0
PassBox.BorderStyle = 1
PassBox.BackColor = vbBlack
PassBox.ForeColor = vbGreen
PassBox.FontSize = 16
PassBox.PasswordChar = "*"
PassBox.Visible = True
PassBox.Enabled = False
End Sub
Private Sub Num0_Click()
PassBox.Text = PassBox.Text & Num0.Caption
End Sub
Private Sub Num1_Click()
PassBox.Text = PassBox.Text & Num1.Caption
End Sub
Private Sub Num2_Click()
PassBox.Text = PassBox.Text & Num2.Caption
End Sub
Private Sub Num3_Click()
PassBox.Text = PassBox.Text & Num3.Caption
End Sub
Private Sub Num4_Click()
PassBox.Text = PassBox.Text & Num4.Caption
End Sub
Private Sub Num5_Click()
PassBox.Text = PassBox.Text & Num5.Caption
End Sub
Private Sub Num6_Click()
PassBox.Text = PassBox.Text & Num6.Caption
End Sub
Private Sub Num7_Click()
PassBox.Text = PassBox.Text & Num7.Caption
End Sub
Private Sub Num8_Click()
PassBox.Text = PassBox.Text & Num8.Caption
End Sub
Private Sub Num9_Click()
PassBox.Text = PassBox.Text & Num9.Caption
End Sub
Private Sub Back_Click()
PassBox.Text = Left(PassBox.Text, Len(PassBox.Text) - 1)
End Sub
Private Sub Cancel_Click()
PassBox.Text = ""
End Sub
Private Sub Enter_Click()
MsgBox "密碼結果=" & PassBox.Text, vbInformation + vbOKOnly, "密碼"
End Sub
uj5u.com熱心網友回復:
白璧微瑕:Private Sub Back_Click()
If PassBox.Text <> "" Then PassBox.Text = Left(PassBox.Text, Len(PassBox.Text) - 1)
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/60982.html
標籤:VB基礎類
上一篇:VB6開三次方問題
