| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1714 人关注过本帖
标题:鼠标经过图片产生缩放变化
只看楼主 加入收藏
sclx88
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2016-7-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
鼠标经过图片产生缩放变化
编译错误,而且我觉得这个代码是不是太繁杂了,有没有简化一点的,如果我有很多个图片框都需要这种效果,要怎么搞
程序代码:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Dim i

    If (X >= Picture1.Left) And (X <= Picture1.Left + Picture1.Width) And _
        (Y >= Picture1.Top) And (Y <= Picture1.Top + Picture1.Height) Then _
        Picture1.Height = 5628
        Picture1.Left = 0
        Picture1.Top = 0
        Picture1.Width = 8376
       
    ElseIf (X < Picture1.Left) And (X > Picture1.Left + Picture1.Width) And _
       (Y < Picture1.Top) And (Y > Picture1.Top + Picture1.Height) Then _
        Picture1.Left = Picture1.Left - 300
        Picture1.Top = Picture1.Top - 150
        Picture1.Width = Picture1.Width + 600
        Picture1.Height = Picture1.Height + 300
    End If
End Sub
搜索更多相关主题的帖子: color 图片 而且 
2016-09-06 14:12
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:941
专家分:5244
注 册:2015-8-10
收藏
得分:10 
这个代码都复杂? 那你的VB可以不用学了。
初步看下来,没有明显的错误。建议把报错信息提供
2016-09-06 16:48
sclx88
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2016-7-31
收藏
得分:0 
回复 2楼 xiangyue0510
编译错误
else 没有IF
 ElseIf (X < Picture1.Left) And (X > Picture1.Left + Picture1.Width) And _
       (Y < Picture1.Top) And (Y > Picture1.Top + Picture1.Height) Then _
这句哪里有问题
我看到有大神是这样写的,但是我仿造用不起
程序代码:
Dim s(3) As Single

 
Private Sub Form_Load()
With Image1
    .Stretch = True
    s(0) = .Left
    s(1) = .Top
    s(2) = .Width
    s(3) = .Height
End With
End Sub

 
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Image1
    If .Left <> s(0) Then .Move s(0), s(1), s(2), s(3)
End With
End Sub

 
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Image1
    If .Left = s(0) Then .Move .Left - 300, .Top - 150, .Width + 600, .Height + 300
End With
End Sub


[此贴子已经被作者于2016-9-6 17:40编辑过]

2016-09-06 17:35
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:10 
你把 换行连接符 去掉,并且把下一行拼上去就会发现错误所在了。

with Picture1
    If (X >= .Left) And (X <= .Left + .Width) And _
        (Y >= .Top) And (Y <= .Top + .Height) Then
        .move 0, 0, 8376, 5628      
    ElseIf (X < .Left) And (X > .Left + .Width) And _
       (Y < .Top) And (Y > .Top + .Height) Then
        .move .Left - 300, .Top - 150, .Width + 600, .Height + 300
    End If
end with

授人于鱼,不如授人于渔
早已停用QQ了
2016-09-06 18:02
sclx88
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2016-7-31
收藏
得分:0 
回复 4楼 风吹过b
问题解决了,但是实际效果点都不好用,鼠标指要晃一下才变,我要的效果是指针放上去放大,移开恢复原样,大神帮我看看下面的代码怎么搞一下,我比较喜欢这种简单明了的
程序代码:
Dim s(3) As Single

 
Private Sub Form_Load()
With Image1
    .Stretch = True
    s(0) = .Left
    s(1) = .Top
    s(2) = .Width
    s(3) = .Height
End With
End Sub

 
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Image1
    If .Left <> s(0) Then .Move s(0), s(1), s(2), s(3)
End With
End Sub

 
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Image1
    If .Left = s(0) Then .Move .Left - 300, .Top - 150, .Width + 600, .Height + 300
End With
End Sub
2016-09-06 19:13
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
试了这些代码,改成 Picture1 也没问题啊。

程序代码:
Option Explicit

Dim s(3) As Single

 
Private Sub Form_Load()
With Picture1
    '.Stretch = True
    s(0) = .Left
    s(1) = .Top
    s(2) = .Width
    s(3) = .Height
End With
End Sub

 
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1
    If .Left <> s(0) Then .Move s(0), s(1), s(2), s(3)          '如果鼠标在窗体上移动时,图像还原大小
End With
End Sub

 
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1
    If .Left = s(0) Then .Move .Left - 300, .Top - 150, .Width + 600, .Height + 300         '如果鼠标在图像内移动时,图像变大
End With
End Sub


如果你有多个 Picture1 ,那就使用控件数组。
同时有一个变量用来标记最后修改大小的那个控件是几号,用于改回去的。

授人于鱼,不如授人于渔
早已停用QQ了
2016-09-07 09:15
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
使用控件数组的办法:
代码里需要指定控件数组有几个元素,看注释。
程序代码:
Option Explicit

Const piccount = 4              '图像个数,0-4 ,共5个
Dim s(piccount, 3) As Single    '保存控件的原始大小数据,与控件数组下标对应
Dim picindex As Integer         '标志最后一个变大的框
 
Private Sub Form_Load()
Dim i As Long
For i = 0 To piccount
    With Picture1(i)
        '.Stretch = True        '根据图像修改框大小,仅适用于Image控件
        s(i, 0) = .Left
        s(i, 1) = .Top
        s(i, 2) = .Width
        s(i, 3) = .Height
    End With
Next i
End Sub

 
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1(picindex)
    If .Left <> s(picindex, 0) Then .Move s(picindex, 0), s(picindex, 1), s(picindex, 2), s(picindex, 3)     '如果鼠标在窗体上移动时,图像还原大小
End With
End Sub

 
Private Sub Picture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1(Index)
    If .Left = s(Index, 0) Then        
        Picture1(picindex).Move s(picindex, 0), s(picindex, 1), s(picindex, 2), s(picindex, 3)     '前一个变小,防止图像放太近造成的干扰
        .Move .Left - 300, .Top - 150, .Width + 600, .Height + 300         '如果鼠标在图像内移动时,图像变大
        picindex = Index                                                       '保存前一个的下标
    End If
End With
End Sub


手动优化了一下代码的可视性

[此贴子已经被作者于2016-9-7 09:31编辑过]


授人于鱼,不如授人于渔
早已停用QQ了
2016-09-07 09:27
sclx88
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2016-7-31
收藏
得分:0 
回复 7楼 风吹过b
谢谢大神,果然解决了
2016-09-07 16:24
快速回复:鼠标经过图片产生缩放变化
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035088 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved