Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   changing image in picture box by clicking image (http://www.xtremevbtalk.com/-net-interface-and-graphics/327291-changing-image-picture-box-clicking-image.html)

FireSlade 09-24-2014 10:37 AM

changing image in picture box by clicking image
 
Hey everyone, I've been searching through the forum trying to find a solution to this problem, and I've seen some similar issues, but not exactly what I need an answer to.

I'm trying to get an image in a picture box to toggle between a large and small version of the same image. I've made 2 picture boxes and overlapped the smaller one on top of the large one. The large picture box visible is set true and small is set false. I can't figure out the code that will allow me to swap those properties, by clicking on the image, so that the small picture becomes true and is visible and the large picture becomes false. This is the code I put for the large picture box:

Private Sub CDPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LargePictureBox.Click
' Large CD image

LargePictureBox.Image = My.Resources.CDROM01
LargePictureBox.Visible = True
SmallPictureBox.Visible = False

End Sub

Small:

Private Sub SmallPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmallPictureBox.Click
' Small CD Image

SmallPictureBox.Image = My.Resources.CDROM01
SmallPictureBox.Visible = True
LargePictureBox.Visible = False

End Sub

I know there's probably a very simple solution to this that I'm completely overlooking, but I just can't get it. Any help would be greatly appreciated. Thanks.

passel 09-24-2014 10:54 AM

You have which picturebox you show reversed.
You can only click on a visible box, so that is the one you want to hide, and show the other.

LargeClick
small.visible

SmallClick
LargeVisible

You shouldn't have to assign the image in each click even.
Just load the image in each picturebox in the Form's Load event.

In Fact, you are loading the image twice in memory, but you could just load it once, and have both pictureboxes reference the same image.

Code:

'In the Form load event
LargePictureBox.Image = My.Resource.CDROM01
SmallPictureBox.Image = LargePictureBox.Image

Private Sub CDPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LargePictureBox.Click
  LargePictureBox.Visible = False
  SmallPictureBox.Visible = True
End Sub

Private Sub SmallPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SmallPictureBox.Click
  SmallPictureBox.Visible = False 
  LargePictureBox.Visible = True
End Sub

I assume you have the SizeMode of the pictureboxes set to Stretch or Zoom, and they are different size pictureboxes.

FireSlade 09-24-2014 11:13 AM

Thank you so much for that information. I had no idea I could just load that image once, as you instructed. Your assumptions were correct, and your corrections worked perfectly. Thanks again.


All times are GMT -6. The time now is 04:40 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.