3

Can anyone please teach me how to detect the event of "clicking on certain part of the same picture" in C#(WindowsForm, to be specific)?

For example, let's just say we have a brain picture in picturebox, and there are three different regions on it : hippocampus, frontal lobe and cortex. How should I detect which region is clicked by user? (Those regions are in irregular shapes.)

Thanks!

wei raven
  • 39
  • 2
  • Oh...I'm sorry...I just thought that I could ask for help... (cuz' I've found some questions similar to this...) – wei raven Jul 18 '16 at 04:50
  • Also [see here!](http://stackoverflow.com/questions/25701778/make-a-map-of-buttons/25703170#25703170) – TaW Jul 18 '16 at 06:53
  • There are lots of ways to do hit-testing. If you want to ask about it here, you have to do some research, try something, and then make sure you include a good [mcve] in your question showing what you've tried, and explain precisely what _specific_ issue you are having trouble solving. Note that the Winforms API does include a `Region` object that supports hit testing via e.g. the [`IsVisible(Point)`](https://msdn.microsoft.com/en-us/library/dz11htdf(v=vs.110).aspx) method. – Peter Duniho Jul 18 '16 at 06:58

1 Answers1

0

Make sure your picture has different colors, if you want similar looking colors make you colors like this: Color.FromArgb(10, 10, 10) and Color.FromArgb(10, 10, 11).

In your click method get the cursor x, y coords (on the screen) and use this method, which will return the color of the pixel.

Set up a switch case or if block, that will determine which part you clicked by the color.

Sorry that there's no code...

Community
  • 1
  • 1
  • 1
    _"Make sure your picture has different colors"_ - well brain CT scans are generally grayscale –  Jul 18 '16 at 03:42
  • Then you could change the grayscale colors slightly like `Color.FromArgb(255, 255, 255)` and `Color.FromArgb(254, 254, 254)`. –  Jul 18 '16 at 04:02
  • No because it's entirely possible that the same pixel intensity (say xf0f0f0) could appear in different regions of the brain. –  Jul 18 '16 at 04:10
  • Okay, true, but what if it's a flat style image, where it's all plain colors? *(Like a .png or .bmp image.)* –  Jul 18 '16 at 04:19
  • Yes agreed then it's totally acceptable. :) –  Jul 18 '16 at 04:28
  • Hey, thanks for the coloring idea. I think it will work in my case. Those pictures I got are not CT scans. But thanks for your reply anyway. – wei raven Jul 18 '16 at 04:54