Which works well enough but there doesn't seem to be a 'simple' way to detect and handle mousing over of each icon.

My idea to do this at the moment is to handle MouseMove events in the PictureBox and send the mouse coords to every visible overlayed icon and do a primitive collision check based on the mouse coords and the icon dimensions.

Is this the best way to go about this? Is there a cleaner way to do it in a C# WinForm application? It doesn't seem particularly clean or efficient but I'm not sure how else I would go about it.

Replies To: Best way to achieve this with WinForm?

Re: Best way to achieve this with WinForm?

Posted 06 July 2010 - 01:42 PM

Since it is a list of icons it seems you may not know if you have 1 or 10 icons overlaid on the main picture.
So the problem with just drawing the icons is that you loose track of the icon as an object.

Personally I think I would handle it in a more object oriented way.

Have a UserControl with the background image, then dynamically add foreground PictreBoxes for each icon, and subscribe your UserControl to each dynamically created picturebox's .Click event.

Now you can detect a click on a foreground PictureBox, and pass that to your parent UserControl.
The UserControl can then raise an event of .Clicked with the object argument being the actual icon picture box... You know where in your event args you have "object sender"? Well make the sender the icon picturebox object.

or some enum indicating they clicked on the "health" or "weapon" or "user" icon. Or on the 5th icon. Or as you need for your project.

Re: Best way to achieve this with WinForm?

Posted 22 July 2010 - 03:45 PM

Coming back to this after working on other things for a while I'm not sure that this solution is going to work as well as I thought. It was acceptable when I was only attempting to overlay a few (very few) icons but as that number grows the app starts to get kind of ugly. When I was just drawing pure bitmaps there were no issues, when I draw PictureBoxes the control becomes a bit sluggish, scrolling the image causes weird artifacts to show up, filtering a specific type of icon on/off (showing and hiding all icons of a certain type) is sluggish, when icons are hidden the bottom of the image often does not go away, scrolling off the background image such that the icons are off the screen then back so they are visible again causes them to be distorted and it feels kind of sloppy overall. I had none of these issues when I was just drawing bitmaps.

Any ideas?

Thanks again.

Edit: Basically, I started this project without fully understanding the extent to which I'd be using graphics. I know that Winform is hardly the premiere graphics rendering tool in 2010. For that reason I've been considering using either HOOPS or switching this to a WPF application. I think either would provide significantly better graphical capabilities. Anyone have an opinion on that?