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]);
            }
        }
    }
  • 相关阅读:
    简单字典操作
    字符串操作
    2017年10月7日
    循环列表练习
    Zabbix4.0系统告警"Zabbix agent on Zabbix server is unreachable for 5 minutes"
    Zabbix4.0系统告警“Zabbix server is not running”
    FreeRADIUS使用了在Cisco IOS配置示例的管理访问
    Cisco AAA Configuration
    使用工具Csvde导出域中所有用户信息
    McAfee Agent卸载方法
  • 原文地址:https://www.cnblogs.com/wrajj/p/5056611.html
Copyright © 2011-2022 走看看