主题:[讨论]关于模拟MouseOver事件和界面设计的问题
天天学习
[专家分:4570] 发布于 2006-10-09 21:48:00
如何作一个按钮,当鼠标移到它上面时,按钮突出显示,移开之后又是一个平面(把鼠标移到菜单上试试就知道了).我用PictureBox模拟,但是效果不理想,因为当我把鼠标移到上面时,不是突出显示,而是凹下去。
用mouseMove事件模拟实现mouseOver事件的处理,代码如下:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim mouseOver As Boolean
mouseOver = (X > 0 And X < Picture1.Width) And (Y > 0 And Y < Picture1.Height)
If mouseOver Then
SetCapture Picture1.hWnd
Picture1.BorderStyle = 1
Else
ReleaseCapture
Picture1.BorderStyle = 0
End If
End Sub
如何实现按钮的突出显示????请教各位高手。
沙发
FieldMAX [专家分:12740] 发布于 2006-10-09 23:02:00
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.Appearance = 0
Picture1.BorderStyle = 0
Picture1.BackColor = &H8000000F
Picture1.Line (0, 0)-(Picture1.ScaleWidth, 0), &H80000010, BF
Picture1.Line (0, 0)-(0, Picture1.ScaleHeight), &H80000010, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(Picture1.ScaleWidth - 15, 15), &H80000015, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(15, Picture1.ScaleHeight - 15), &H80000015, BF
Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth("CommandBox")) / 2
Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight("CommandBox")) / 2
Picture1.Print "CommandBox"
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim mouseOver As Boolean
mouseOver = (X > 0 And X < Picture1.Width) And (Y > 0 And Y < Picture1.Height)
If mouseOver Then
SetCapture Picture1.hWnd
Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), &H8000000F, BF
Picture1.Line (0, 0)-(Picture1.ScaleWidth, 0), &H80000016, BF
Picture1.Line (0, 0)-(0, Picture1.ScaleHeight), &H80000016, BF
Picture1.Line (15, 15)-(Picture1.ScaleWidth, 15), &H80000016, BF
Picture1.Line (15, 15)-(15, Picture1.ScaleHeight), &H80000016, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(Picture1.ScaleWidth - 15, 15), &H80000015, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(15, Picture1.ScaleHeight - 15), &H80000015, BF
Picture1.Line (Picture1.ScaleWidth - 30, Picture1.ScaleHeight - 30)-(Picture1.ScaleWidth - 30, 30), &H80000010, BF
Picture1.Line (Picture1.ScaleWidth - 30, Picture1.ScaleHeight - 30)-(30, Picture1.ScaleHeight - 30), &H80000010, BF
Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth("CommandBox")) / 2 - 15
Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight("CommandBox")) / 2 - 15
Picture1.Print "CommandBox"
Else
ReleaseCapture
Picture1.Line (0, 0)-(Picture1.ScaleWidth, Picture1.ScaleHeight), &H8000000F, BF
Picture1.Line (0, 0)-(Picture1.ScaleWidth, 0), &H80000010, BF
Picture1.Line (0, 0)-(0, Picture1.ScaleHeight), &H80000010, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(Picture1.ScaleWidth - 15, 15), &H80000015, BF
Picture1.Line (Picture1.ScaleWidth - 15, Picture1.ScaleHeight - 15)-(15, Picture1.ScaleHeight - 15), &H80000015, BF
Picture1.CurrentX = (Picture1.ScaleWidth - Picture1.TextWidth("CommandBox")) / 2
Picture1.CurrentY = (Picture1.ScaleHeight - Picture1.TextHeight("CommandBox")) / 2
Picture1.Print "CommandBox"
End If
End Sub