Home > Archive > Visual Basic Syntax > February 2005 > Picture Box
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I am new to VB6. I have 2 picture box. I want to load different picture in
pic box 1 when pic box 2 is click. with my following code I am getting type
mismatch error. help pls!
Private Sub Form_Load()
picture1.Picture = LoadPicture(App.Path & "\image\ant.bmp")
picture2.picture = Loadpicture(App.Path & "\image\bat.bmp")
End Sub
Private Sub picture2_Click()
If picture1.Picture = ("\image\ant.bmp") Then
picture1.picture = loadpicture(app.path & "\image\ant1.bmp")
else
beep
End If
End Sub
| |
| Björn Holmgren 2005-02-04, 9:06 am |
| "zonga" <zonga@discussions.microsoft.com> wrote in message
news:D3F7614E-AA6D-4EEE-9525-4E8BE4444CE0@microsoft.com...
> I am new to VB6. I have 2 picture box. I want to load different picture in
> pic box 1 when pic box 2 is click. with my following code I am getting
type
> mismatch error. help pls!
> Private Sub Form_Load()
> picture1.Picture = LoadPicture(App.Path & "\image\ant.bmp")
> picture2.picture = Loadpicture(App.Path & "\image\bat.bmp")
> End Sub
>
> Private Sub picture2_Click()
> If picture1.Picture = ("\image\ant.bmp") Then
> picture1.picture = loadpicture(app.path & "\image\ant1.bmp")
> else
> beep
> End If
> End Sub
The picturebox doesn't store the path to the loaded picture, so you the IF
statement in Picture2_Click will fail. I suggest you store the path in the
Tag property each time you load a new picture:
Private Sub Form_Load()
Picture1.Tag = App.Path & "\image\ant.bmp"
Picture1.Picture = LoadPicture(Picture1.Tag)
Picture2.Tag = App.Path & "\image\bat.bmp"
Picture2.Picture = LoadPicture(Picture2.Tag)
End Sub
Private Sub picture2_Click()
If Picture1.Tag = App.Path & "\image\ant.bmp" Then
Picture1.Tag = App.Path & "\image\ant1.bmp"
Picture1.Picture = LoadPicture(Picture1.Tag)
Else
Beep
End If
End Sub
--
Björn Holmgren
| |
|
| Hi Bjorn Holmgren, Thanks for help.
"Björn Holmgren" wrote:
> "zonga" <zonga@discussions.microsoft.com> wrote in message
> news:D3F7614E-AA6D-4EEE-9525-4E8BE4444CE0@microsoft.com...
> type
>
> The picturebox doesn't store the path to the loaded picture, so you the IF
> statement in Picture2_Click will fail. I suggest you store the path in the
> Tag property each time you load a new picture:
>
> Private Sub Form_Load()
> Picture1.Tag = App.Path & "\image\ant.bmp"
> Picture1.Picture = LoadPicture(Picture1.Tag)
> Picture2.Tag = App.Path & "\image\bat.bmp"
> Picture2.Picture = LoadPicture(Picture2.Tag)
> End Sub
>
> Private Sub picture2_Click()
> If Picture1.Tag = App.Path & "\image\ant.bmp" Then
> Picture1.Tag = App.Path & "\image\ant1.bmp"
> Picture1.Picture = LoadPicture(Picture1.Tag)
> Else
> Beep
> End If
> End Sub
>
>
> --
> Björn Holmgren
>
>
>
>
|
|
|
|
|