How to dynamically assign a wmf file to a picturebox

241 Views Asked by At

I have a VB6 legacy that uses 100's of .wmf files I'm now creating the same application with Visual Studio 2019 VB.NET I am experiencing a problem with dynamically changing a picturebox from the default .wmf file to a new one. I've tested the code to change to a .jpg image with no problem. (see code below - the output replaces the original .wmf image and then toggles between blank and the .jpg image)

Static Toggle As Boolean
Dim FName As String = ""
If Toggle Then
    FName = "D:\VB6\06ST.jpg"
Else
    FName = "D:\VB6\06ST.wmf"
End If
Toggle = Not Toggle
PictureBox1.Image = Image.FromFile(FName)

Is there a way to overcome this problem?

1

There are 1 best solutions below

1
On

Move this line:

Toggle = Not Toggle

into the else condition.

Either that or I don't understand the question.