标题:VB6.0使用Image控件作为按钮使用,在切换图片的时候,为什么会闪一下?
只看楼主
小刀神
Rank: 1
等 级:新手上路
帖 子:69
专家分:5
注 册:2018-5-27
结帖率:91.67%
已结贴  问题点数:18 回复次数:4 
VB6.0使用Image控件作为按钮使用,在切换图片的时候,为什么会闪一下?
VB6.0使用Image控件作为按钮使用,在切换图片的时候,为什么会闪一下?
MouseDown事件以及MouseUp事件,这两个事件是会切换Image控件的Picture的
使用的是LoadPicture函数加载图片
每次切换图片的时候,Image控件都会闪烁一下,很难受,有大神知道解决方法的么?
部分代码如下:
程序代码:
Dim User
Dim User01
Dim User02 As String
Dim Order As String
Dim Order01
Dim UserAccount As String
Dim UserEncryption As String
Dim UserEncryption01
Dim UserAccountRandomNumber As String
Dim UserAccountRandomNumber01
Dim UserAccount01 As String
Dim 取字符 As String
Dim UserPassword As String
Dim UserPasswrodRandomNumber As String
Dim UserPasswordRandomNumber01
Dim UserPasswordEncryption As String
Dim UserPasswordEncryption01
Dim UserPassword01 As String
Dim ImagePath As String
Dim ImagePath01 As String
Public ImagePath02
Dim Image_登录_Change As Integer
Dim Image_退出_Change As Integer
Private Sub Form_Load()
Image_登录_Change = 0
Image_背景.Left = 0
Image_背景.Width = Form_登录.Width
Image_背景.Height = Form_登录.Height
Open "C:\LieMengWrite\Image\ImagePath.ini" For Input As #1 '读入图片素材路径信息
Do While Not EOF(1)
Line Input #1, ImagePath
ImagePath01 = ImagePath01 & ImagePath
Loop
Close #1
ImagePath02 = Split(ImagePath01, ";")
End Sub


Private Sub Image_背景_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ImageChange
If Image_登录_Change = 1 Then
    ImageChange = Split(ImagePath02(0), "=")
    Image_登录按钮.Picture = LoadPicture(ImageChange(1))
    Image_登录_Change = 0
End If
If Image_退出_Change = 1 Then
    ImageChange = Split(ImagePath02(3), "=")
    Image_退出.Picture = LoadPicture(ImageChange(1))
    Image_退出_Change = 0
End If
End Sub

Private Sub Image_登录按钮_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ImageChange
If Button = 1 Then
    ImageChange = Split(ImagePath02(2), "=")
    Image_登录按钮.Picture = LoadPicture(ImageChange(1))
End If
End Sub

Private Sub Image_登录按钮_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ImageChange
ImageChange = Split(ImagePath02(1), "=")
If Image_登录_Change = 0 Then
    Image_登录按钮.Picture = LoadPicture(ImageChange(1))
    Image_登录_Change = 1
End If
End Sub

Private Sub Image_登录按钮_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ImageChange
ImageChange = Split(ImagePath02(0), "=")
If Button = 1 Then
    Image_登录按钮.Picture = LoadPicture(ImageChange(1))
        计次 = 0
    Open "C:\LieMengWrite\User\UserAccount.LMW" For Input As #1 '读取用户信息文本文件
    Do While Not EOF(1)
    Line Input #1, User
    User02 = User02 & User
    Loop 'Until EOF(1)
    Close #1
    User01 = Split(User02, ";")
    Open "C:\LieMengWrite\User\Order\UserOrder.LMW" For Input As #1 '读取Order文件信息
    Do While Not EOF(1)
    Line Input #1, Order
    Order01 = Split(Order, ";")
    Loop
    Close #1
    If Order01(0) = "0" Then
        UserAccount = User01(0)
        UserPassword = User01(1)
    Else
        UserAccount = User01(1)
        UserPassword = User01(0)
    End If
    Open "C:\LieMengWrite\User\UserEncryption\User01.LMW" For Input As #1
    Do While Not EOF(1)
    Line Input #1, UserEncryption
    Loop
    Close #1
    UserEncryption01 = Split(UserEncryption, ";")
    Open "C:\LieMengWrite\User\RandomNumber\UserAccountRandomNumber.LMW" For Input As #1
    Do While Not EOF(1)
    Line Input #1, UserAccountRandomNumber
    Loop
    Close #1
    UserAccountRandomNumber01 = Split(UserAccountRandomNumber, ";")
    Open "C:\LieMengWrite\User\RandomNumber\UserPasswordRandomNumber.LMW" For Input As #1
    Do While Not EOF(1)
    Line Input #1, UserPasswordRandomNumber
    Loop
    Close #1
    UserPasswordRandomNumber01 = Split(UserPasswordRandomNumber, ";")
    Open "C:\LieMengWrite\User\UserEncryption\User02.LMW" For Input As #1
    Do While Not EOF(1)
    Line Input #1, UserPasswordEncryption
    Loop
    Close #1
    UserPasswordEncryption01 = Split(UserPasswordEncryption, ";")
If Text_账号.Text = "" Then
    'Print "账号不能为空"
    MsgBox "账号不能为空", , "警告"
Else
    If Text_密码.Text = "" Then
       
        'Print "密码不能为空"
        MsgBox "密码不能为空", , "警告"
      'a = MsgBox("密码", vbYesNo, "提示")
    Else
        取字符 = Left(Text_账号.Text, 1)
        UserAccount01 = UserEncryption01(0) & 取字符 & UserAccountRandomNumber01(0) & Text_账号.Text & UserEncryption01(1) & UserAccountRandomNumber01(1)
        If UserAccount01 = UserAccount Then
            取字符 = Left(Text_密码.Text, 1)
            UserPassword01 = UserPasswordEncryption01(0) & 取字符 & UserPasswordRandomNumber01(0) & Text_密码.Text & UserPasswordEncryption01(1) & UserPasswordRandomNumber01(1)
            If UserPassword01 = UserPassword Then
                'Print "登陆成功"
                MsgBox "登陆成功", , "警告"
                Form_登录.Hide
                Form_写作.Show
            Else
                'Print "账号或密码错误"
                MsgBox "账号或密码错误", , "警告"
            End If
            
        Else
            'Print "账号或密码错误"
            MsgBox "账号或密码错误", , "警告"
        End If
    End If
End If
End If
End Sub
搜索更多相关主题的帖子: Dim 登录 Input End If 
2018-06-23 22:56
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:0 
初步静态看了一下,先看到一个小问题,
Image_背景.Width = Form_登录.Width
Image_背景.Height = Form_登录.Height

width 是控件总的宽度,在屏幕显示时占用宽度,这个宽度包括左右边框
height 总高度,除了上下边框外,还包括了标题栏的高度。
VB6提供了一组属性
ScaleWidth、ScaleHeight
这二个属性指示 除掉边框、标题栏 剩余的可以用于显示内容的 宽度和高度,就是有效宽度和高度,
显示内容时的坐标就是基于这个属性来的。

另外,如果仅在窗体内部引用自身窗体属性时,建议使用 me 关键字,代码窗体名字。
可以防止 需要修改窗体名时,导致大量的修改问题。

---------------------------------

我测试了三种切换图像的命令,都会闪烁。你自己试试看。

程序代码:
Private Sub Command1_Click()        '直接传送源图像
Image1.Picture = Image2.Picture
End Sub

Private Sub Command2_Click()        '直接IO加载图像
Image1.Picture = LoadPicture("C:\Users\Administrator\Desktop\2.gif")
End Sub

Private Sub Command3_Click()            '使用 PropertyBag 对象传递图像
Dim PBag As New PropertyBag

PBag.WriteProperty "Picture", Image2.Picture
Set Image1.Picture = PBag.ReadProperty("Picture")
End Sub

Private Sub Form_Load()
Image2.Move -Image2.Width        '隐藏原始图像
End Sub


方法1:要求窗体上有一大堆 image 控件或控件数组。
方法2:临时读,受IO性能影响。
方法3:窗体上可以只有一个image控件,读取PropertyBag后可以转换为byte数组缓存到内存中。可以使用结构体数组来。

Image控件,连 直接传送源图像 都闪烁,

授人于鱼,不如授人于渔
早已停用QQ了
2018-06-24 10:46
小刀神
Rank: 1
等 级:新手上路
帖 子:69
专家分:5
注 册:2018-5-27
得分:0 
回复 2楼 风吹过b
多谢指点,让我多学到了一些东西,不过我的窗体使用的是没有标题栏的那种
主要想问问有没有什么控件或方法,在切换图像的时候,是不会闪烁的?
2018-06-24 14:09
xzlxzlxzl
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖北
等 级:贵宾
威 望:125
帖 子:1091
专家分:5825
注 册:2014-5-3
得分:7 
image控件有图片自适应大小的功能,也许是读取的原始图像像素过大,会使读取和画像速度更不上,造成闪烁,建议用ps先减小图片尺寸再加载试试。
2018-06-24 22:22
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:11 
那你换成 picturebox 控件试试。

换图像,使用 PaintPicture 复制图像进行贴图,可以做到不闪烁。

还有一种就是界面就是 一张图,自己用代码绘制控件切换效果和捕捉鼠标坐标和位置,生成响应事件。



授人于鱼,不如授人于渔
早已停用QQ了
2018-06-24 22:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-488106-1-1.html




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

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