zoukankan      html  css  js  c++  java
  • 在ListBox中实现右键菜单,需要注意的细节



    本段代码实现的目标:
      blue区域不显示contextmenu,橙色范围显示contextmenu
      就是当mouse右键点击listbox中的存在项上,才显示contextmenu,其他范围不显示contextmenu.
    private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       if(e.Button == MouseButtons.Right)
       {
        //listBoxItem Total Height
        int listBoxItemToTalHeight = listBox1.Items.Count * listBox1.ItemHeight;
        int currentIndex = e.Y /12;
        if(SqlInt32.Mod(currentIndex,12) == 0)
        {
         currentIndex = currentIndex;
        }
        if(e.Y > listBoxItemToTalHeight)
        {
         this.listBox1.ContextMenu = this.contextMenu1;
         contextMenu1.MenuItems[0].Visible = false;
        }
        else
        {
         this.listBox1.ContextMenu = this.contextMenu1;
         contextMenu1.MenuItems[0].Visible = true;
         if(listBox1.SelectedItem != null && currentIndex != listBox1.SelectedIndex)
         {
          this.listBox1.SetSelected(listBox1.SelectedIndex,false);
         }
         this.listBox1.SetSelected(currentIndex,true);
         this.listBox1.ContextMenu.Show(listBox1,new Point(e.X,e.Y));
        }
       } 
      }

  • 相关阅读:
    平摊分析的应用
    平摊分析--势能法
    平摊分析--会计法
    平摊分析--聚集法
    算法设计与分析总结
    动态规划--前缀动态规划问题
    【例】动态规划--最长回文序列问题
    分治法--中位数与顺序统计量
    动态规划--数轴动态规划问题
    pymssql模块官方文档的翻译
  • 原文地址:https://www.cnblogs.com/RuiLei/p/380401.html
Copyright © 2011-2022 走看看