Question How to change the picture of a button while it is clicked

trinque

Member
Joined
Jul 6, 2013
Messages
6
Programming Experience
Beginner
I have a button on my web browser, I want the picture to change while I am clicking it. I have no idea how to do this and would greatly appreciate if somebody could tell me how I go about making this happen.
 
Last edited:
Your post is a bit incoherent. The title talks about a TextBox while the post talks about a WebBrowser and a Button and none of it really explains what picture you're talking about. Please try again and, this time, provide a FULL and CLEAR description of the problem.
 
It's clearer but still not exactly devoid of ambiguity. Are you talking about a regular Button control on a Windows Forms or a button on the web page? Do you mean the image on the button or in the web browser or something else? When I said FULL and CLEAR that is what I meant. You're expecting us to assume a lot and, if we make the wrong assumption, we waste everyone's time.
 
Ok, I am making a web browser in visual basic. I have a button to make the web browser go back and it has a picture set as the background with no text. I want it so that when I click the button it will change the image set for the button but only for as long as I have it pressed down. I hope that clears all misunderstandings about my question. Once again I apologize for being so vague.
 
OK, that is a clear description and is the sort of thing you should strive for in future. To do that, you would handle the MouseDown and MouseUp events. When the user depresses the mouse button it will raise the MouseDown event and MouseUp is raised when the mouse button is released. In those event handlers, you can assign a new Image to the Image or BackgroundImage property as appropriate.

You will probably want to handle the MouseEnter and MouseLeave events too. Try creating a new project with a Button on a form and watch how the Button behaves when you depress the mouse button over it and then drag the mouse out of and back into its area. You'll probably want to implement something similar. You'll need to to handle the situation where the depresses the mouse button over your Button, drags off and then releases.
 

Latest posts

Back
Top