How can I change the image on the picture box when the mouse is over the picture box I know how to end the application when the mouse is over the picture box but what is the code for changing the picture C++ (I need to use mouse enter class)

Image type is .png

Recommended Answers

All 13 Replies

C++ has no inherent understanding of a mouse, a picture or a window. This is all heavily dependent on your chosen operating system and your chosen window manager.

Your wrong because i know it's possible i have done it before it was easy i dont know if its my question but what i need is picture box is going to load a diffrent image when the mouse over and when the mouse is not over it's going to go back to the image before and it should be easy the picture all in one location!

He's using .NET (C++/CLI). OP, you should specify this (at least that you are using a Winforms project).

MSDN has great pages on all of the controls. You'll find that you need to change the BackgroundImage (and probably the BackgroundImageLayout). http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox(v=VS.100).aspx

I'm not talking about background image i want to cahnge the image on picture box 1 C++ windows form application

That's the property of the PictureBox that you want to change. How have you set the image on the picturebox thusfar? Please read the link that I gave you or find a suitable tutorial on the subject.

Yes there is an already iamge and im using the mouse enter class when the mouse it over the picture picture will be change to something else!

Through what method have you placed the image in the picturebox? Show the code that you use to initialize it. I have found it is easiest to set the image as "BackgroundImage" of the picturebox and then change it by replacing that BackgroundImage with a new one.

i didnt write any code it doesnt require code for puttting pics and i dont want background image if i do that that will rune my design my i know that system drawing might help me and you

Well, it certainly requires code to change the picture. Did you put the picture in through the properties window on the right side of the IDE?

I think you're misinterpreting background image here. I'm not talking about the Windows background, I'm talking about the image that is displayed in the picture box. I've never had any luck using the PictureBox.Image in this fashion, that's why I'm recommending setting and changing the backgroundimage of the picturebox, not whatever you have for the background of your application or the Windows background.

i know what you said i think i missexplained i already set an image for the picture box through properties and i have done nothing else!

Mate i need to sleep its late here i keep writting tomorrow if you can find anything just write i read it tomorrow

You didn't found anything anyideas any other way to do this

If you have set the image as a PictureBox Image using the properties window, you just change the image in your MouseEnter handler. You'll need a MouseLeave handler setting the picture back to what it was if you want that effect.

In the MouseEnter: yourPictureBoxNameHere->Image = Image::FromFile(YourNewImagePathString); In the MouseLeave: yourPictureBoxNameHere->Image = Image::FromFile(YourOriginalImagePathString); I'm not sure what the big deal was, you were 3/4 of the way there. I was suggesting you use the BackgroundImage property (which can be set in the Properties window just like the Image property can) because there's more control over how the image is placed. I did it your way with the Image and the picturebox came out scaled funny (I'm sure there's a way to change this with Image, but I was offering you a suggestion I was familiar with).

THanks just what i needed they were couple errors but it's fine now. Thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.