简体   繁体   English

如何制作图片框触发器mousedoubleclick?

[英]How to make picturebox trigger mousedoubleclick?

I'm using a Win Form VS 2010 C#. 我正在使用Win Form VS 2010 C#。

I have the following code on the Form Load 我在Form Load上有以下代码

pictureBox2.MouseClick +=new MouseEventHandler(pictureBox2_Click);
pictureBox2.DoubleClick += new EventHandler(pictureBox2_Click);
pictureBox2.Click += new EventHandler(pictureBox2_Click);
pictureBox2.MouseDoubleClick += new MouseEventHandler(pictureBox2_Click);

and this on the Event 这是在事件上

private void pictureBox2_Click(object sender, EventArgs e)
{
    // Hides and disables another picture box
    pictureBox1.Enabled = false;
    pictureBox1.Visible = false;
    // more codes here...
}

It does not want to fireup the Event. 它不想启动事件。 I've even added the toggle breakpoint just to be sure but it never stops there. 我甚至添加了切换断点只是为了确定但它永远不会停在那里。

My pictureBox2 has a property BackColor Transparent. 我的pictureBox2有一个属性BackColor Transparent。 Does this have anything to do with it? 这与它有什么关系吗?

It sounds like everything should work, so my thoughts are: 听起来一切都应该有效,所以我的想法是:

  1. What happens if you use .Click instead of .MouseClick? 如果您使用.Click而不是.MouseClick会发生什么? Any difference? 有什么区别?

  2. What happens if you move the event handler creation into InitializeComponent() (or right after InitializeComponent()) instead of in the form load event? 如果将事件处理程序创建移动到InitializeComponent()(或在InitializeComponent()之后)而不是在表单加载事件中,会发生什么? Any difference? 有什么区别?

  3. Is there some sort of issue with another control on top of your picture box receiving the click instead of your picturebox? 接收点击而不是图片框的图片框顶部有另一个控件存在某种问题吗?

  4. If you suspect that the transparent backcolor might be a problem, why not change it and see if that fixes the problem? 如果您怀疑透明背景颜色可能是一个问题,为什么不更改它,看看是否能解决问题? Then you'll have your answer. 然后你会得到答案。

  5. ( SOLUTION ) EDIT added for clarification after @HenryHughes commented that he eventually solved the original problem by simply re-creating the Visual Studio project from scratch. 解决方案 )在@HenryHughes评论说他最终通过简单地从头重新创建Visual Studio项目后解决了原始问题后添加了编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM