Picturebox控件未触发鼠标事件 [英] Picturebox control not firing mouse events

查看:286
本文介绍了Picturebox控件未触发鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2010下开发的VB winform应用程序的groupbox控件中有一个picturebox控件.我使用设计器像往常一样添加MouseClick()事件.在我的代码中,我这样创建了一个位图:

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)

并将其分配给Picturebox控件:

and assign it to the picturebox control:

pbSprites.Image = bmSource 

到目前为止,到目前为止,启动应用程序时,我看到了较大的小位图.问题在于,只有在单击外部较小的位图但仍在另一个内部时,才触发MouseClick()事件. bmSprite大约是bmSource大小的三分之一.

请注意,bmSource也是一个拖放源,但是这似乎不是问题,因为当我删除拖放代码时,它仍然不起作用.另外,如果我将位图加载到pbSprite中,而不是在内存中创建一个位图,则可以正常工作.为什么这样创建位图会引起问题?

谢谢!

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!

推荐答案

好吧,我打败了.我添加了另一个控件,将其连接起来并删除了旧的控件,它运行良好.您生活和学习....
Well, it beats me. I added another control, hooked it up and deleted the old control and it worked fine. You live and learn....


这篇关于Picturebox控件未触发鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆