当用户在其中一个选项上输入特定值时锁定按钮
Lock button when user put a specific value on one of the choices
当用户输入四个房间之一的金额时,我想锁定其他按钮。相反,如果我无法锁定,请帮我做其他事情,而当用户单击其他房间时,其他房间将冻结为 0 值。
Public Class Formrooms
Dim birthday As Double
Dim party As Double
Dim vip As Double
Dim deluxe As Double
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblparty.BackColor = ColorTranslator.FromHtml("#100F0E")
lblbday.BackColor = ColorTranslator.FromHtml("#100F0E")
lblvip.BackColor = ColorTranslator.FromHtml("#100F0E")
lbldeluxe.BackColor = ColorTranslator.FromHtml("#100F0E")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnbirthday_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnvip_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndeluxe_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
lblparty.Text -= 1
If lblparty.Text <= 0 Then
lblparty.Text = 0
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
lblbday.Text -= 1
If lblbday.Text <= 0 Then
lblbday.Text = 0
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
lblvip.Text -= 1
If lblvip.Text <= 0 Then
lblvip.Text = 0
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
lbldeluxe.Text -= 1
If lbldeluxe.Text <= 0 Then
lbldeluxe.Text = 0
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
lblparty.Text += 1
If lblparty.Text >= 3 Then
lblparty.Text = 3
End If
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
lblbday.Text += 1
If lblbday.Text >= 3 Then
lblbday.Text = 3
End If
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
lblvip.Text += 1
If lblvip.Text >= 3 Then
lblvip.Text = 3
End If
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
lbldeluxe.Text += 1
If lbldeluxe.Text >= 3 Then
lbldeluxe.Text = 3
End If
End Sub
Private Sub Number_only(sender As Object, e As KeyPressEventArgs)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
Dim dialog As DialogResult
If lblbday.Text = 0 And lbldeluxe.Text = 0 And lblparty.Text = 0 And lblvip.Text = 0 Then
dialog = MessageBox.Show("You must choose the rooms", "Error", MessageBoxButtons.OK)
ElseIf lblbday.Text > 0 And lblparty.Text >= 1 And lblvip.Text = 1 And lbldeluxe.Text > 1 Then
dialog = MessageBox.Show("You can only choose 1 room", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
Private Sub btnbackr_Click(sender As Object, e As EventArgs) Handles btnbackr.Click
Me.Hide()
Formtakeorders.Show()
End Sub
Private Sub lblparty_Click(sender As Object, e As EventArgs) Handles lblparty.Click
End Sub
End Class
我不太明白,但我认为这是解决方案。
[1]: https://i.stack.imgur.com/D62kl.png [例子][1]
如果我不帮助你解决这个问题,我想解释一下你想做的事情
' 命名我的按钮:房间 1、房间 2、房间 3、房间 4
'示例 Dim ButtonRoom As Button = CType(Me.Controls("Room" & j), Button)
' 将我的按钮命名为:hello1、hello2、hello3、hello4
'example2 Dim ButtonRoom As Button = CType(Me.Controls("hello" & j), Button)
Private Sub Room1_Click(sender As Object, e As EventArgs) Handles Room1.Click
selected_room(1)
End Sub
Private Sub Room2_Click(sender As Object, e As EventArgs) Handles Room2.Click
selected_room(2)
End Sub
Private Sub Room3_Click(sender As Object, e As EventArgs) Handles Room3.Click
selected_room(3)
End Sub
Private Sub Room4_Click(sender As Object, e As EventArgs) Handles Room4.Click
selected_room(4)
End Sub
Public Function selected_room(ByVal i As Integer)
For j As Integer = 1 To 4
Dim ButtonRoom As Button = CType(Me.Controls("<name your button here>" & j), Button)
If j = i Then
ButtonRoom.Enabled = True
Else
ButtonRoom.Enabled = False
End If
Next j
Return True
End Function
如果您没有从解决方案中受益,希望您与我联系
instagram : ovhc_
如果我对你有帮助,请投我一票。
如果我能从你糟糕的解释中找出真正的意思,这种事情就可以了:
Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles Button4.Click,
Button3.Click,
Button2.Click,
Button1.Click
For Each btn In Controls.OfType(Of Button)()
btn.Enabled = btn Is sender
Next
End Sub
为所有 Buttons
设置一个事件处理程序,然后为每个 Button
设置 Enabled
属性。 sender
是引发事件的对象,即被单击的 Button
。除了 Button
之外的所有内容都不是 sender
所以除了 Button
之外的所有内容都将其 Enabled
属性 设置为 False
.
请注意,这假设所有这些 Buttons
都在同一个容器中 - 在这种特定情况下是表单 - 并且该容器不包含其他 Buttons
。如果当前不是这种情况,您可以 hard-code Buttons
的列表进行循环或仅将那些 Buttons
移动到新容器中,例如Panel
.
我认为您应该去掉四个按钮(派对、生日、贵宾、豪华),只使用一个“下一步”按钮。然后,每当您增加其中一个房间值时,只需将其他小时选择重置为零即可:
Public Class Formrooms
Dim party As Integer
Dim birthday As Integer
Dim vip As Integer
Dim deluxe As Integer
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
If party > 0 Then
party = party - 1
lblparty.Text = party
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
If birthday > 0 Then
birthday = birthday - 1
lblbday.Text = birthday
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
If vip > 0 Then
vip = vip - 1
lblvip.Text = vip
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
If deluxe > 0 Then
deluxe = deluxe - 1
lbldeluxe.Text = deluxe
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
party = Math.Min(party + 1, 3)
lblparty.Text = party
birthday = 0
vip = 0
deluxe = 0
lblbirthday.Text = birthday
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
birthday = Math.Min(birthday + 1, 3)
lblbday.Text = birthday
party = 0
vip = 0
deluxe = 0
lblparty.Text = party
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
vip = Math.Min(vip + 1, 3)
lblvip.Text = vip
party = 0
birthday = 0
deluxe = 0
lblparty.Text = party
lblbirthday.Text = birthday
lbldeluxe.Text = deluxe
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
deluxe = Math.Min(deluxe + 1, 3)
lbldeluxe.Text = deluxe
party = 0
birthday = 0
vip = 0
lblparty.Text = party
lblbirthday.Text = birthday
lblvip.Text = vip
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
If birthday = 0 AndAlso deluxe = 0 AndAlso party = 0 AndAlso vip = 0 Then
MessageBox.Show("You must choose a room with at least one hour.", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
End Class
当用户输入四个房间之一的金额时,我想锁定其他按钮。相反,如果我无法锁定,请帮我做其他事情,而当用户单击其他房间时,其他房间将冻结为 0 值。
Public Class Formrooms
Dim birthday As Double
Dim party As Double
Dim vip As Double
Dim deluxe As Double
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblparty.BackColor = ColorTranslator.FromHtml("#100F0E")
lblbday.BackColor = ColorTranslator.FromHtml("#100F0E")
lblvip.BackColor = ColorTranslator.FromHtml("#100F0E")
lbldeluxe.BackColor = ColorTranslator.FromHtml("#100F0E")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnbirthday_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btnvip_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndeluxe_Click(sender As Object, e As EventArgs)
Me.Hide()
Formsnacks.Show()
End Sub
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
lblparty.Text -= 1
If lblparty.Text <= 0 Then
lblparty.Text = 0
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
lblbday.Text -= 1
If lblbday.Text <= 0 Then
lblbday.Text = 0
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
lblvip.Text -= 1
If lblvip.Text <= 0 Then
lblvip.Text = 0
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
lbldeluxe.Text -= 1
If lbldeluxe.Text <= 0 Then
lbldeluxe.Text = 0
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
lblparty.Text += 1
If lblparty.Text >= 3 Then
lblparty.Text = 3
End If
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
lblbday.Text += 1
If lblbday.Text >= 3 Then
lblbday.Text = 3
End If
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
lblvip.Text += 1
If lblvip.Text >= 3 Then
lblvip.Text = 3
End If
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
lbldeluxe.Text += 1
If lbldeluxe.Text >= 3 Then
lbldeluxe.Text = 3
End If
End Sub
Private Sub Number_only(sender As Object, e As KeyPressEventArgs)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
Dim dialog As DialogResult
If lblbday.Text = 0 And lbldeluxe.Text = 0 And lblparty.Text = 0 And lblvip.Text = 0 Then
dialog = MessageBox.Show("You must choose the rooms", "Error", MessageBoxButtons.OK)
ElseIf lblbday.Text > 0 And lblparty.Text >= 1 And lblvip.Text = 1 And lbldeluxe.Text > 1 Then
dialog = MessageBox.Show("You can only choose 1 room", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
Private Sub btnbackr_Click(sender As Object, e As EventArgs) Handles btnbackr.Click
Me.Hide()
Formtakeorders.Show()
End Sub
Private Sub lblparty_Click(sender As Object, e As EventArgs) Handles lblparty.Click
End Sub
End Class
我不太明白,但我认为这是解决方案。 [1]: https://i.stack.imgur.com/D62kl.png [例子][1]
如果我不帮助你解决这个问题,我想解释一下你想做的事情
' 命名我的按钮:房间 1、房间 2、房间 3、房间 4
'示例 Dim ButtonRoom As Button = CType(Me.Controls("Room" & j), Button)
' 将我的按钮命名为:hello1、hello2、hello3、hello4
'example2 Dim ButtonRoom As Button = CType(Me.Controls("hello" & j), Button)
Private Sub Room1_Click(sender As Object, e As EventArgs) Handles Room1.Click
selected_room(1)
End Sub
Private Sub Room2_Click(sender As Object, e As EventArgs) Handles Room2.Click
selected_room(2)
End Sub
Private Sub Room3_Click(sender As Object, e As EventArgs) Handles Room3.Click
selected_room(3)
End Sub
Private Sub Room4_Click(sender As Object, e As EventArgs) Handles Room4.Click
selected_room(4)
End Sub
Public Function selected_room(ByVal i As Integer)
For j As Integer = 1 To 4
Dim ButtonRoom As Button = CType(Me.Controls("<name your button here>" & j), Button)
If j = i Then
ButtonRoom.Enabled = True
Else
ButtonRoom.Enabled = False
End If
Next j
Return True
End Function
如果您没有从解决方案中受益,希望您与我联系 instagram : ovhc_
如果我对你有帮助,请投我一票。
如果我能从你糟糕的解释中找出真正的意思,这种事情就可以了:
Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles Button4.Click,
Button3.Click,
Button2.Click,
Button1.Click
For Each btn In Controls.OfType(Of Button)()
btn.Enabled = btn Is sender
Next
End Sub
为所有 Buttons
设置一个事件处理程序,然后为每个 Button
设置 Enabled
属性。 sender
是引发事件的对象,即被单击的 Button
。除了 Button
之外的所有内容都不是 sender
所以除了 Button
之外的所有内容都将其 Enabled
属性 设置为 False
.
请注意,这假设所有这些 Buttons
都在同一个容器中 - 在这种特定情况下是表单 - 并且该容器不包含其他 Buttons
。如果当前不是这种情况,您可以 hard-code Buttons
的列表进行循环或仅将那些 Buttons
移动到新容器中,例如Panel
.
我认为您应该去掉四个按钮(派对、生日、贵宾、豪华),只使用一个“下一步”按钮。然后,每当您增加其中一个房间值时,只需将其他小时选择重置为零即可:
Public Class Formrooms
Dim party As Integer
Dim birthday As Integer
Dim vip As Integer
Dim deluxe As Integer
Private Sub btndecp_Click(sender As Object, e As EventArgs) Handles btndecp.Click
If party > 0 Then
party = party - 1
lblparty.Text = party
End If
End Sub
Private Sub btndecb_Click(sender As Object, e As EventArgs) Handles btndecb.Click
If birthday > 0 Then
birthday = birthday - 1
lblbday.Text = birthday
End If
End Sub
Private Sub btndecv_Click(sender As Object, e As EventArgs) Handles btndecv.Click
If vip > 0 Then
vip = vip - 1
lblvip.Text = vip
End If
End Sub
Private Sub btndecd_Click(sender As Object, e As EventArgs) Handles btndecd.Click
If deluxe > 0 Then
deluxe = deluxe - 1
lbldeluxe.Text = deluxe
End If
End Sub
Private Sub btnincp_Click(sender As Object, e As EventArgs) Handles btnincp.Click
party = Math.Min(party + 1, 3)
lblparty.Text = party
birthday = 0
vip = 0
deluxe = 0
lblbirthday.Text = birthday
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincb_Click(sender As Object, e As EventArgs) Handles btnincb.Click
birthday = Math.Min(birthday + 1, 3)
lblbday.Text = birthday
party = 0
vip = 0
deluxe = 0
lblparty.Text = party
lblvip.Text = vip
lbldeluxe.Text deluxe
End Sub
Private Sub btnincv_Click(sender As Object, e As EventArgs) Handles btnincv.Click
vip = Math.Min(vip + 1, 3)
lblvip.Text = vip
party = 0
birthday = 0
deluxe = 0
lblparty.Text = party
lblbirthday.Text = birthday
lbldeluxe.Text = deluxe
End Sub
Private Sub btnincd_Click(sender As Object, e As EventArgs) Handles btnincd.Click
deluxe = Math.Min(deluxe + 1, 3)
lbldeluxe.Text = deluxe
party = 0
birthday = 0
vip = 0
lblparty.Text = party
lblbirthday.Text = birthday
lblvip.Text = vip
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles nextr.Click
If birthday = 0 AndAlso deluxe = 0 AndAlso party = 0 AndAlso vip = 0 Then
MessageBox.Show("You must choose a room with at least one hour.", "Error", MessageBoxButtons.OK)
Else
Me.Hide()
formsnacks.Show()
End If
End Sub
End Class