简体   繁体   English

VB6按键上的动态图像更改

[英]Dynamic image change on keypress VB6

So I'm trying to make this form in VB6 with just an image, and whenever you press say the "Q" key that image changes, and if you press "E" it changes to back to the previous one. 因此,我试图在VB6中仅使用一张图片制作此表格,每当您按“ Q”键时,图片就会更改,如果您按“ E”,它将更改为上一张。 Simple stuff. 简单的东西。

Here's what I have: 这是我所拥有的:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 81 Then Image.Picture = LoadPicture("E:\Imagenes\Avatars\4.jpg")
If KeyAscii = 69 Then Image.Picture = LoadPicture("E:\Imagenes\Avatars\3.gif")
End Sub

Well, that doesn't work. 好吧,那是行不通的。 What could I do to make it work? 我该怎么做才能使其正常工作? Thanks! 谢谢!

In reading your comment, you say that you are using the Default Image Control, there is not a Default Image Control you need to add an instance of it to your Form or just use the Forms Picture Property. 在阅读评论时,您说的是使用的是默认图像控件,没有默认图像控件,您不需要将其实例添加到窗体中或仅使用窗体图片属性。

These examples work for me: 这些示例对我有用:

Private Sub Form_KeyPress(KeyAscii As Integer)
    If (Chr(KeyAscii) = "Q" Or Chr(KeyAscii) = "q") Then Form1.Picture = LoadPicture("E:\Imagenes\Avatars\4.jpg")
    If (Chr(KeyAscii) = "E" Or Chr(KeyAscii) = "e") Then Form1.Picture = LoadPicture("E:\Imagenes\Avatars\3.gif")
End Sub

and

Private Sub Form_KeyPress(KeyAscii As Integer)
    If (Chr(KeyAscii) = "Q" Or Chr(KeyAscii) = "q") Then Image1.Picture = LoadPicture("E:\Imagenes\Avatars\4.jpg")
    If (Chr(KeyAscii) = "E" Or Chr(KeyAscii) = "e") Then Image1.Picture = LoadPicture("E:\Imagenes\Avatars\3.gif")
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM