[英]Multiple Buttons keypad in VB.net
I have been battling with this for three days and asked a LOT of people the question, but maybe I'm asking it wrong. 我已经与之抗争了三天,并问了很多人这个问题,但也许我问错了。 The project that I'm working , is to create a digital safe lock.
我正在工作的项目是创建一个数字安全锁。 I need to achieve the following:
我需要实现以下目标:
I created a keypad with six buttons in a group box. 我在组框中创建了带有六个按钮的键盘。 When one click on the buttons, then the digit being clicked must be displayed in the listbox.
一按按钮时,必须在列表框中显示被单击的数字。 As you press the rest (up to six digits max) the all have to be displayed in the listbox, next to each other in sequence like the way one will press the buttons on a calculator and then the listbox must display them in the same way.
当您按下其余字符(最多六位数字)时,所有内容都必须显示在列表框中,并依次显示,就像一个人按下计算器上的按钮,然后列表框必须以相同的方式显示它们一样。 Here is whet I have figured out up to date:
这是我最新发现的:
Public Class Form1
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
If pinlst.Items.Count = 0 Then
pinlst.Items.Add(btn1.Text)
Else
pinlst.Items(0).SubItems.Add(btn1.Text)
End If
End Sub
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
If pinlst.Items.Count = 1 Then
pinlst.Items.Add(btn2.Text)
Else
pinlst.Items(1).SubItems.Add(btn2.Text)
End If
End Sub
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
If pinlst.Items.Count = 2 Then
pinlst.Items.Add(btn3.Text)
Else
pinlst.Items(2).SubItems.Add(btn3.Text)
End If
End Sub
Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
pinlst.Text = btn4.Text
End Sub
Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
pinlst.Text = btn5.Text
End Sub
Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
pinlst.Text = btn6.Text
End Sub
Private Sub btngp_Enter(sender As Object, e As EventArgs) Handles btngp.Enter
pinlst.Text = pinlst.Text & btn1.Text
pinlst.Text = pinlst.Text & btn2.Text
pinlst.Text = pinlst.Text & btn3.Text
pinlst.Text = pinlst.Text & btn4.Text
pinlst.Text = pinlst.Text & btn5.Text
pinlst.Text = pinlst.Text & btn6.Text
End Sub
End Class
It's best to assign every button to a character being pressed or a function being performed, in design time. 最好在设计时将每个按钮分配给被按下的字符或正在执行的功能。 For this to work, you need to have every button as a custom control, based off a regular button of course, exposing a property "CharPressed" or something like that.
为此,您需要将每个按钮都作为自定义控件,当然要基于常规按钮,并且要公开“ CharPressed”属性或类似属性。 Then you can have a single static handler for all buttons, which you will wire dynamically in
Sub New
, after InitializeComponent
. 然后,您可以为所有按钮使用一个静态处理程序,您将在
InitializeComponent
之后在Sub New
动态进行连线。 If this does not make sense, please feel free to ask a question in comments. 如果这没有意义,请随时在评论中提问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.