zoukankan      html  css  js  c++  java
  • winform程序实现ListBox 双击选中项执行函数

    标题很诱人,google、baidu了一通都没有找到解决方案,于是自己想了下。其实对于ListBox本身是没有实现双击选中项这个函数的,需要自己程序实现,

    下面是我的方式,发上来共享一下,不足之处请指出

               //lbTables是一个ListBox的实例。首先判断是否选中项为一项,如果是一项,然后判断鼠标双击的那个点是否落在那个双击项的矩形框里,是的执行自己的

              //函数,搞定

       if (lbTables.SelectedItems.Count == 1)
                {
                    Rectangle rec= lbTables.GetItemRectangle(lbTables.SelectedIndex);
                    int left = rec.Left;
                    int right = rec.Right;
                    int top = rec.Top;
                    int bottom = rec.Bottom;
                    if (e.X > left && e.X < right && e.Y > top && e.Y < bottom)
                    {
                        _lstLeftTables.Remove(lbTables.SelectedValue.ToString());
                        _lstRightTables.Add(lbTables.SelectedValue.ToString());
                        BindData();
                    }
                }

    ps:其实可以自己继承ListBox将这个事件重写了,分发个ItemDoubleClick事件。

  • 相关阅读:
    __attribute__((noreturn))的用法
    selenium定位元素的方法
    zzz
    go语言的第一个helloworld
    mac eclipse 创建Java 工程
    Jmeter:图形界面压力测试工具
    使用 HAProxy, PHP, Redis 和 MySQL 轻松构建每周上亿请求Web站点
    从Log4j迁移到LogBack的理由
    SLF4J和Logback日志框架详解
    security with restful
  • 原文地址:https://www.cnblogs.com/yukun/p/1584008.html
Copyright © 2011-2022 走看看