zoukankan      html  css  js  c++  java
  • 获取相对于控件的鼠标坐标

    最近使用Emgu开发计算机视觉相关软件,但是里面的ImageBox控件自定义事件比较多,很烦人,而且winform不支持直接从控件获取相对于控件的鼠标坐标。这两点就导致我要想在ImageBox上绘制一些东西比较麻烦,解决如下:

    1、获取相对于控件的鼠标坐标;

    解决方法很简单:

    Point x = imageBox1.PointToClient(Form1.MousePosition);
    label2.Text = x.X.ToString() + " | " + x.Y.ToString();

    2、去掉控件的EventHandler的所有绑定事件;

    这个稍微麻烦,这里贴上stackoverflow粘过来的答案,经测试,不可使用,但是这个思路应该是可行的。最后我用winform自带的PictureBox显示视频。

    public partial class Form1 : Form
    {
            public Form1()
            {
                InitializeComponent();
    
                button1.Click += button1_Click;
                button1.Click += button1_Click2;
                button2.Click += button2_Click;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Hello");
            }
    
            private void button1_Click2(object sender, EventArgs e)
            {
                MessageBox.Show("World");
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                RemoveClickEvent(button1);
            }
    
            private void RemoveClickEvent(Button b)
            {
                FieldInfo f1 = typeof(Control).GetField("EventClick", 
                    BindingFlags.Static | BindingFlags.NonPublic);
                object obj = f1.GetValue(b);
                PropertyInfo pi = b.GetType().GetProperty("Events",  
                    BindingFlags.NonPublic | BindingFlags.Instance);
                EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);
                list.RemoveHandler(obj, list[obj]);
            }
        }
    }
  • 相关阅读:
    Use Visual studio 2010 build Python2.7.10
    ext4 disable journal
    ElasticSearch优化配置
    重载Python FTP_TLS 实现Implicit FTP Over TLS方式下载文件
    linux下对进程按照内存使用情况进行排序
    python 树遍历
    E: Unable to correct problems, you have held broken packages 解决方法
    C++ Lambda 表达式使用详解
    C++ 14 新特性总结
    Log4j配置
  • 原文地址:https://www.cnblogs.com/wrajj/p/5056611.html
Copyright © 2011-2022 走看看