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
求改错!! 展开
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
求改错!! 展开
4个回答
展开全部
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
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
展开全部
你有代码没有错,运行正常,符合你的要求。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-12-11
展开全部
你看下《老兵新传:Visual Basic核心编程及通用模块开发》第8.5节,“为静态图形添加图形热区”,网上有目录可以参考。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把下面的代码粘贴到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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询