1.可以利用picture.mousemove()事件实现放大效果.即当鼠标经过时,图像的长宽分别加上一个固定值.实现"放大"效果.不过要注意就是,要先设置一个判断标志----放大了一次后就不要再放大了.不然,当鼠标一直在上面时,不断触发这个事件,会不断变大,与设想效果不同.
但,picutre控件本身没有鼠标离开事件,无法实现缩小.
2.幸好,窗体 form本身也有mousemove事件.并且,当鼠标经过窗体中控件表面时,
不会触发窗体本身的mousemove事件.那么.利用这点.以下程序演示实现LZ要求.
VB6中新建工程,一个窗体,窗体上放置一个picture控件.图像什么随便设置.大小也是自己设置
全部代码如下:
Dim ch As Boolean '图像改变大小标志
Private Sub Form_Load()
ch = False '程序运行时,鼠标肯定还没有经过图像,所以,假
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If ch Then '已经放大了,则缩小,当鼠标离开图像时.
Picture1.Width = Picture1.Width - 200 '这个值200和以下的300自己改吧
Picture1.Height = Picture1.Height - 300
ch = False
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not ch Then '鼠标经过,且,还没有放大过.放大一次.
Picture1.Width = Picture1.Width + 200 '这个值200和以下的300自己改吧
Picture1.Height = Picture1.Height + 300
ch = True
End If
End Sub
Dim ch As Boolean '图像改变大小标志
Private Sub Form_Load()
ch = False '程序运行时,鼠标肯定还没有经过图像,所以,假
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If ch Then '已经放大了,则缩小,当鼠标离开图像时.
Picture1.Width = Picture1.Width - Picture1.Width / 6 '这个值200和以下的300自己改吧
Picture1.Height = Picture1.Height - Picture1.Height / 6
Picture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
ch = False
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not ch Then '鼠标经过,且,还没有放大过.放大一次.
Picture1.Width = Picture1.Width + Picture1.Width / 5 '这个值200和以下的300自己改吧
Picture1.Height = Picture1.Height + Picture1.Height / 5
Picture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
ch = True
End If
End Sub
Private Sub Picture1_Paint()
Picture1.AutoRedraw = True
Picture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End Sub
广告 您可能关注的内容 |