• How to make a picture appear\dissapear when the button is pressed\depressed in VB?
    4 replies, posted
I just started playing around with a copy of Visual Studio 2008, and can't figure out how to do this. I have this to make the image appear when the button is pressed: [code]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = True End Sub[/code] But I want to make it so that the image only stays visible when the button is pushed down, and when you release the button, it goes back to being invisible. My first thought was this: [code]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = True PictureBox1.Visible = False End Sub[/code] But as you all probably already know, that just made it so that the image becomes visible and then invisible as soon as you hit the button and you don't even know it became visible. Anybody know how to do this?
[code]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = Not PictureBox1.Visible End Sub[/code] [editline]10:07AM[/editline] er.. just realized what you're trying to do, you should use the "MouseDown" and "MouseUp" events instead (not sure if those are the right events, haven't used VB.NET much really)
That makes it so that you have to click again to hide the image. I guess it would make it easier if I explained what I plan to do with it... Basically I'm going to take an image of text and cut it into a grid, so that you have to remember what it looked like to get the whole message, and then you need to enter that into a text box. Pretty much a really simple puzzle game.
[code]Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown PictureBox1.Visible = True End Sub Private Sub Button1_MouseUp(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp PictureBox1.Visible = False End Sub [/code] Does that work?
Exactly what I was looking for, thanks.
Sorry, you need to Log In to post a reply to this thread.