Click here to Skip to main content
14,385,144 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a picturebox control in a groupbox control on a VB winform app I'm developing under VS2010. I use the designer to add a MouseClick() event as you would normally. In my code I create a bitmap thus:

Dim bmSource As Bitmap = New Bitmap(nWidth, nHeight,System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
(sorry about the Hungarian notation!) and then create another bitmap which will be rendered into the above bitmap:
Dim bmSprite As New Bitmap(48, 42, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
Dim g As Graphics = Graphics.FromImage(bmSource) g.DrawImage(bmSprite, nXPos * 48, nYPos * 42)
and assign it to the picturebox control:
pbSprites.Image = bmSource 
So far so good, I see the small bitmap in the large one when I start the app. The problem is the MouseClick() event is only ever triggered when I click outside the smaller bitmap but still inside the other one. bmSprite is about a third of the size of bmSource.

Note that bmSource is also a drag and drop source, but that doesn't seem to be the problem as it still doesn't work when I remove the drag and drop code. Also, If I load a bitmap into pbSprite, rather than creating one in memory, it works OK. Why would creating the bitmap like this cause a problem?

Thanks!
Posted
Updated 1-Nov-19 11:45am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Well, it beats me. I added another control, hooked it up and deleted the old control and it worked fine. You live and learn....
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Same problem, same mysterious solution in VS 2019 - add a new control and it fires events OK
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100