我想在标签上将 MouseEnter 与 MousePressed 结合起来。
Public Sub populateGrid()
lblTest.BackColor()
lblTest.BackColor = System.Drawing.Color.Red
gbWorkflow.Controls.Add(lblTest)
For j As Integer = 1 To 40
For i As Integer = 1 To 20
Dim L As New Label
L.Size = New Size(30, 30)
L.Text = "L:" + i.ToString + j.ToString
L.BackColor = Color.AliceBlue
Dim x, y As Integer
Dim loc As Point = gbWorkflow.Location
y = loc.Y * (i * 8) '- (gbWorkflow.Height + L.Size.Height) * i
x = loc.X * (j * 8)
L.Location = New Point(x, y)
gbWorkflow.Controls.Add(L)
AddHandler L.MouseEnter, AddressOf L_Enter
AddHandler L.MouseLeave, AddressOf L_Leave
Next
Next
End Sub
Private Sub L_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
Dim TheLabel As Label = CType(sender, Label)
TheLabel.BackColor = Color.Red
End Sub
我的想法是创建一个在 MouseDown 上触发并更改布尔变量值的方法。然后,我将使用该变量作为将更改应用于标签的条件。然而,这似乎不起作用......
我怎样才能以最好的方式实现这一目标?或者,根本没有?
伪代码:当鼠标输入标签时:如果按下鼠标左键,则使用标签执行操作
编辑:当仍然按下鼠标按钮并将光标拖到多个标签上时,它也必须工作。按下左键时光标穿过的所有标签都应更改。