image的问题.在线等````

qinyue 2004-02-03 10:32:17
我有一个窗口上面只放IMAGE控件,窗口的大小也IMAGE的大小相同.我想实现只要鼠标放在IMAGE图上IMAGE就换一张指定好的图(这已实现),当鼠标移开IMAGE时IMAGE将指定另一张图(这是在什么事件里写?)
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2004-04-25
  • 打赏
  • 举报
回复
因为窗口的大小与IMAGE的大小相同,可以用TIMER 控件来实现:


'取得窗体位置的函数
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
Private Sub Form_Load()
Image1.Stretch = True
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Image1.Picture = LoadPicture("d:\3.jpg")
End Sub

Private Sub Timer1_Timer()
Dim MyRect As RECT
Dim MyPoint As POINTAPI

' MyRect返回当前窗口位置
GetWindowRect Me.hwnd, MyRect

' MyPoint返回当前鼠标位置
GetCursorPos MyPoint
If MyPoint.x < MyRect.Left Or MyPoint.x > MyRect.Right Or MyPoint.y < MyRect.Top Or MyPoint.y > MyRect.Bottom Then Image1.Picture = LoadPicture("d:\1.jpg")
End Sub
BlueBeer 2004-04-24
  • 打赏
  • 举报
回复
建议换成picturebox

'用到一个API,声明如下:
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long

'窗体上内放一个picturebox,添加代码:
Private Sub Form_Load()
SetCapture Picture1.hWnd
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > 0 And X < Picture1.Width And Y > 0 And Y < Picture1.Height Then
Me.Caption = "in box"
'把这里换成你对图片的设定代码就行了
Else
Me.Caption = "out box"
'把这里换成你对图片的设定代码就行了
End If
End Sub
射天狼 2004-04-24
  • 打赏
  • 举报
回复
用有句柄的控件可以实现,比如PICTURE!!

Public Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long

Private Sub picClose_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If X > 0 And X < picClose.Width And Y > 0 And Y < picClose.Height Then
If Button = vbLeftButton Then
picClose.Picture = imgCloseDown.Picture
Else
picClose.Picture = imgCloseMove.Picture
End If
SetCapture picClose.hWnd
Else
picClose.Picture = imgClose.Picture
ReleaseCapture
End If
End Sub
huazhongxu 2004-04-24
  • 打赏
  • 举报
回复
用MouseHook来解决,先取得当前窗体(Client区域)相对于屏幕的坐标(即:绝对坐标),然后取得鼠标移动时的绝对坐标,判断是否在该Client区域,一旦不在就更换另外一张图。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧