简体   繁体   中英

How to find if mouse click is on an image rendered in a wf panel?

First let me say I love this site and often find the answers to my questions before I ever have to post. Now I have a question that I can't seem to find an answer to. Let me also mention that I'm somewhat new to programming and have only been doing it a few months.

With that out of the way here is whats going on.

I have a panel with a system.drawing graphics attached to it so I can render out pictures.

With these pictures that I render to the panel I want to be able to move them around, and then interact with them with and rotate them. Kinda like a jigsaw puzzle.

I can get the images to render, but need a way to tell if my mouse is over the picture that was last rendered in that location. Since an image might render overtop of another image I want to get the top/last rendered image.

Currently i have the images in a list that get rendered and I do have a couple of ideas of my own.

  1. On a mouse click I scan all the image list last to first and find one that is currently being rendered in that spot and that would be my image.

  2. Re render the screen last to first and as soon as a pixel changes where my mouse is that is my image.

  3. Assign each pixel a image value and when rendering the image the pixels that are on it get assigned that image and the mouse can just pull that image.

Any help or feedback would be much appreciated.

Thank you.

The method you use will probably be largely dependent on your application. Without knowing much about what you're trying to do solution 3 seems the best.

With option 3 the majority of the work is being carried out as you add each image (ie assigning its value to the pixels it covers). The other options are are probably going to be less computationally expensive when you add the images but more expensive every mouse click. Assuming that this suits your application (which it most probably does if its similar to a jigsaw as you stated) I'd go with something like that.

It also assumes that your images are rectangular shapes where values can be added based on the corners rather than an arbitrary shape in which all points in the image must be manually calculated. With an arbitrary shape working out which method will be quicker will be more difficult to work out.

In summary, you'd be best to decide what operation will be carried out more often (adding images or mouse clicks) and carry out the work at the other one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM