vb中如何实现当鼠标经过时标签变为红色,过去后还原为原色?

代码如下:dimAasVariantPrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,Y... 代码如下:
dim A as Variant
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label2.ForeColor = A
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label2.ForeColor = vbRed
End Sub
求改错!!
展开
 我来答
风雪剑无痕
2012-11-28 · TA获得超过1253个赞
知道大有可为答主
回答量:1691
采纳率:100%
帮助的人:1659万
展开全部
Dim A As Variant
Private Sub Form_Load()
A = Label2.ForeColor
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label2.ForeColor = A
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label2.ForeColor = vbRed
End Sub
sxqiufeng
2012-12-04 · TA获得超过644个赞
知道小有建树答主
回答量:647
采纳率:100%
帮助的人:486万
展开全部
你有代码没有错,运行正常,符合你的要求。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2012-12-11
展开全部
你看下《老兵新传:Visual Basic核心编程及通用模块开发》第8.5节,“为静态图形添加图形热区”,网上有目录可以参考。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友cc16d5c
2012-11-28 · TA获得超过731个赞
知道小有建树答主
回答量:647
采纳率:50%
帮助的人:528万
展开全部
把下面的代码粘贴到Form1的代码窗口,可以满足你的要求。不用MouseMove事件是因为在鼠标移动过快的情况下会出现颜色不改变的情况。
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim x1, y1, x2, y2 'Label1在窗口客户区的左上角坐标和右下角坐标(单位:像素)
Dim cLeft, cTop '坐标偏移(单位:像素)
Private Sub Form_Load()
'窗体的ScaleMode属性保持默认的“1 - Twip”不需改变
Dim tx, ty
With Screen
tx = .TwipsPerPixelX
ty = .TwipsPerPixelY
End With
With Label2
x1 = .Left \ tx
y1 = .Top \ ty
x2 = x1 + .Width \ tx - 1
y2 = y1 + .Height \ ty - 1
End With
With Me
cLeft = (.Width - .ScaleWidth) / tx / 2
cTop = (.Height - .ScaleHeight) / ty - cLeft
End With
End Sub
Private Sub Timer1_Timer()
'Timer1的属性设置:Enable = True,Interval=100
Dim mp As POINTAPI, mwr As RECT
Dim mx, my
Static ox, oy
Call GetCursorPos(mp)
Call GetWindowRect(Me.hwnd, mwr)
mx = mp.X - mwr.Left - cLeft
my = mp.Y - mwr.Top - cTop
If mx = ox And my = oy Then Exit Sub
ox = mx
oy = my
With Label2
If mx < x1 Or mx > x2 Or my < y1 Or my > y2 Then
.BackColor = vbWindowBackground
Else
.BackColor = vbRed
End If
End With
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式