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.

1

There are 1 best solutions below

2
On BEST ANSWER

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.