Hello all,
I would like to switch between two images displayed in a canvas. When the user clicks on the canvas, if image A is already displayed, then that one is replaced by image B. I created a subclass of the Canvas, added return true to the mouse down event, created a ‘click’ event definition and in the mouse up event added a RaiseEvent command.
I also have a property for ImageA As Boolean.
In the Paint event I have code:
If ImageA = False Then
g.DrawPicture(ImageA, 0, 0)
ImageA = True
Else
ImageA = False
g.DrawPicture(ImageB, 0, 0)
End If
I cannot figure out how to get the paint event to fire following the initial load of the object on start up.
Can anyone shed some light on how this is done?
Hi Tim,
I had not tried Invalidate before your post - thank you.
However, if I put it in the paint event after the end if, it goes into an endless loop.
If I add Invalidate to the Click Event, then it does display the second image, but it also displays the first image as well!
So how to remove or hide images so only one is displayed?
Oops! I wen into autopilot there and spaced on that. However, I get the update on my tests with no further interaction. Are you certain that the paint event is getting called? Are are you instantiating the image in a tight loop that may be blocking updates?
To be clear, the image gets drawn each time. However the previous image(s) are also visible too…
So I need to clear the canvas somehow before the next image is drawn.
Tim
[quote=54567:@Tim Seyfarth]This fixed the problem, but not sure if it is really the correct method for doing this.
g.ClearRect(0,0, Me.Width, Me.Height)
[/quote]
Do you have EraseBackground set to false?
There are far too many Tims in this conversation (not really, you can never have too many Tims).
What I was getting at was to use the BackDrop as the picture assignment instead of the Paint event. Since all that you seem to be trying to do is paint the proper decoration for that section of your controls (portrait or landscape), there’s no need to get any fancier (unless I’ve missed something).
BTW - I’m near the Fields at Talking Stick off of Via de Ventura. However, I’m in Kauai right now. It’s been raining and it’s glorious!
[quote=54622:@Tim Jones]There are far too many Tims in this conversation (not really, you can never have too many Tims).
[/quote]
Canadians would believe you can never have too many Tims
You’re technically disqualified from posting in this thread, but since your post was Tim-related, I fixed it for you.
Canadians would believe you can never have too many Tims
To get an idea of how devoted Canadians are to Tim’s they pour 77% of ALL coffee poured outside the home.
In Canada McDonald’s has 7% and Starbucks has about 3% of the market