如果视觉工作室中的颜色为红色,请尝试隐藏按钮上的标签

时间:2015-11-16 15:29:36

标签: visual-studio-2012

这仅适用于标签发件人,但我也需要将其用于按钮发件人,这样只有在单击按钮时标签为红色才能隐藏。 我有48个座位 Private Sub Label_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Seat9.Click,Seat8.Click,Seat7.Click,Seat6.Click,Seat5.Click,Seat48.Click,Seat47.Click,Seat46.Click ,Seat45。点击,Seat44。点击,Seat43。点击,Seat42.Click,Seat41.Click,Seat40。点击,Seat4Click,Seat39。点击,Seat38。点击,Seat37.Click,Seat36。点击,Seat35。点击,Seat34点击,Seat33。点击,Seat32.Click,Seat31。点击,Seat30。点击,Seat3.Click,Seat29。点击,Seat28。点击,Seat27。点击,Seat26。点击,Seat25。点击,Seat24。点击,Seat23。点击,Seat22.Click,Seat21.Click,Seat20.Click,Seat2.Click,Seat19.Click,Seat18.Click,Seat17.Click,Seat16.Click,Seat15.Click,Seat14.Click,Seat13.Click,Seat12.Click,Seat11 。点击,Seat10.Click,Seat1.Click

Dim Seats As Label = CType(sender, Label)

    If Seats.BackColor = Color.White Then

        Seats.BackColor = Color.Red

    Else

        Seats.BackColor = Color.White

    End If

1 个答案:

答案 0 :(得分:0)

好的,我想我现在明白了。
您有多个代表座位的标签,当用户点击标签时,它们会从白色变为红色。
您想要创建一个单击按钮,它会从屏幕/表单中删除所有红色标签。
您可以将以下内容放在按钮的单击事件中(假设您的表单名为frmMain)

For Each c As Control in frmMain.Controls
 Dim l As Label = DirectCast(c, Label) ' Cast from control to label
 If Not l Is Nothing ' If this control is indeed a label then process
   If l.BackColor = Color.Red Then ' If color is red then hide label
     l.Visible = False
   Else
    l.Visible = True
   End If
  l.Visible = False
 End If
Next

我没有把VS拉起来,所以语法可能有点不正确,但我认为你明白了。