I am drawing a square image with transparent background inside a pictureBox inside a Form with C#. I only want it to capture the mouse events with its visible part, but it happens that it captures events with its whole surface.
Asked
Active
Viewed 82 times
1 Answers
1
This will work for SizeMode of Normal and AutoSize:
if (new Bitmap(((PictureBox)sender).Image).GetPixel(e.X, e.Y).A >= 8)
// do stuff
otherwise you would probably have to do some calculations to get the pixel location.
If this works for you, you should also consider storing the bitmap in a variable instead of newing it up on every mouse event.
EDIT: I used 8 just as a delta value instead of zero to leave some space for almost completely transparent pixels, but of course you don't have to.

Neme
- 492
- 3
- 14
-
I just tried it and it worked perfectly for me. And that delta thing resulted to be very useful for my special case. Thanks! – Dec 22 '16 at 02:50
-
I'm just wondering if this is correct even for higher DPIs. Maybe somebody can comment on that. – Neme Dec 22 '16 at 03:00