zoukankan      html  css  js  c++  java
  • winform右键菜单

     1 public partial class Form1 : Form  
     2     {  
     3         ContextMenuStrip cms;  
     4         Bitmap bm ;  
     5         public Form1()  
     6         {  
     7             InitializeComponent();  
     8         }  
     9         private void Form1_MouseDown(object sender, MouseEventArgs e)  
    10         {  
    11               
    12             if (e.Button == MouseButtons.Right)  
    13             {  
    14                 if (cms.Items.Count > 0)  
    15                 {  
    16                     cms.Items.Clear();  
    17                 }  
    18                 //带图表项  
    19                 cms.Items.Add("tubiao",bm,new EventHandler(tubiao_Handler));  
    20                 cms.Items.Add("mouseright1");  
    21                 cms.Items.Add("-");  
    22                 cms.Items.Add("mouseright2");  
    23                 cms.Items.Add("-");  
    24                 cms.Items.Add("mouseright3");  
    25             }  
    26             else 
    27             {  
    28                 return;  
    29             }  
    30             //处理显示位置  
    31             int w= Width-e.X;  
    32             if (w < cms.Width)  
    33             {  
    34                 cms.Show(this, e.X - cms.Width, e.Y);  
    35             }  
    36             else 
    37             {  
    38                 cms.Show(this,e.X,e.Y);  
    39             }  
    40  
    41         }  
    42         public void tubiao_Handler(object sender, EventArgs e)  
    43         {  
    44             MessageBox.Show("this is tubiao", "tubiao", MessageBoxButtons.YesNo);  
    45         }  
    46         private void Form1_Load(object sender, EventArgs e)  
    47         {  
    48             cms = new ContextMenuStrip();  
    49             bm = new Bitmap("Resources/Icon1.ico");//图标存放位置  
    50         }  
    51     }  
  • 相关阅读:
    c++运算符重载
    c++ const_cast
    SHL
    C++拷贝构造函数(深拷贝,浅拷贝)
    ps命令详解
    static 修饰符
    “宝洁八大问”整理篇
    linux grep命令
    C++操作符重载
    linux中删除指定日期之前的文件
  • 原文地址:https://www.cnblogs.com/hanc/p/3685978.html
Copyright © 2011-2022 走看看