Hi, how i can set background image toToolStripMenuItem in c# at testToolStripMenuItem_MouseHover and testToolStripMenuItem_MouseLeave events. I have tried this but it doesn't work for me..

testToolStripMenuItem.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Button\\BIGBUTTON\\Test Centre-OVER.jpg");

When i put MouseHover on testToolStripMenuItem it will display one blue spot on particular after mouse leave image will be set. i dont understand what happening out their

In short i want to display two images from mouse hover and leave. How i can do this..

Thanks in Advance..

Recommended Answers

All 4 Replies

I assume that on the mouse hover and leave events you are assigning the right image.
Then, do you call testToolStripMenuItem.Invalidate after assigning the new image to force the redraw of the control?

Hope this helps

Is their is any method or property ToolStripMenuItem.Invalidate . can you expalin it i dont understand call testToolStripMenuItem.Invalidate after assigning the new image to force the redraw of the control?

The ToolStripMenuItem.Invalidate method forces to redraw the control.
This will show the right image you set.
See here

Hope this helps

Is the background image being covered by the highlighted border? If so, you'll probably have to override a Renderer class, and wrap the default ToolStripRenderer to achieve this. See this thread. It's been a while since I've done much with WinForms, but I believe this is quite an involved process. WPF allows for quite a bit more visual customization, if you are able to switch.

Also, you shouldn't be calling Image.FromFile() in each of the events. I could be wrong, but I don't believe this method caches the images for subsequent calls. You should call it once in the constructor of the Form and store it as a local variable.

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.