VB.鼠标移进移出的问题。
想要达到这样的效果,即有数组label1,5个,当鼠标移进label时,label1背景颜色改变为蓝色,移出时恢复原来颜色。当鼠标点击label时,label颜色为红色,...
想要达到这样的效果,即有数组 label1,5个,当鼠标移进label时,label1背景颜色改变为蓝色,移出时恢复原来颜色。当鼠标点击label时,label颜色为红色,鼠标移动到其他label时仍变为蓝色,点击变为红色的除外。例如微博中选项的效果。如图,求代码。谢谢
展开
4个回答
展开全部
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Label1(i).ForeColor = &H80000008
Next
End Sub
Private Sub Label1_Click(Index As Integer)
Label1(Index).ForeColor = &HFF&
End Sub
Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 4
Label1(i).ForeColor = IIf(Label1(i).ForeColor <> &HFF&, &H80000008, &HFF&)
Next
Label1(Index).ForeColor = IIf(Label1(Index).ForeColor <> &HFF&, &H80000002, &HFF&)
End Sub
Dim i As Integer
For i = 0 To 4
Label1(i).ForeColor = &H80000008
Next
End Sub
Private Sub Label1_Click(Index As Integer)
Label1(Index).ForeColor = &HFF&
End Sub
Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 4
Label1(i).ForeColor = IIf(Label1(i).ForeColor <> &HFF&, &H80000008, &HFF&)
Next
Label1(Index).ForeColor = IIf(Label1(Index).ForeColor <> &HFF&, &H80000002, &HFF&)
End Sub
更多追问追答
追问
这代码 ,点击之后,鼠标回去没办法恢复原来颜色啊。当点击全部的时候 全部为红色了。我要的是点击的那个除外,其他移动的都变。
追答
刚才代码是点击过了的就是红色;你是说只有点击时才红,移开依然黑色?
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Label1(i).ForeColor = &H80000008
Next
End Sub
Private Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1(Index).ForeColor = &HFF&
End Sub
Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 4
Label1(i).ForeColor = &H80000008 'IIf(Label1(i).ForeColor &HFF&, &H80000008, &HFF&)
Next
Label1(Index).ForeColor = IIf(Label1(Index).ForeColor &HFF&, &H80000002, &HFF&)
End Sub
展开全部
vb中label不能直接加载图片,你可以用VB.Net 来做就简单多了,或者换别的控件,移进移出好实现,
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbRed
End Sub
移出可以Form_MouseMove,点击加个变量表示状态,没完全实现就不贴代码了,当顶下共同学习了
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbRed
End Sub
移出可以Form_MouseMove,点击加个变量表示状态,没完全实现就不贴代码了,当顶下共同学习了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
iisheng的回答百分百地干净利落,在Form_MouseMove事件里重复一遍Form_Load事件的代码即可
更多追问追答
追问
重复之后 之前点击为红色的那个label也变为蓝色了!!但我要的是点击的那个红色不变,当点击另一个label的时候,原先那个红色变为原始颜色,鼠标移动到还是蓝色的效果。
追答
在Label1_MouseDown事件里记录index为静态变量,然后在Form_MouseMove事件里排除即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询