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#面向对象--类
    Unity DOTS--面向数据编程前的准备
    C#面向对象--命名空间
    C#面向对象--多态
    C#面向对象--继承
    C#中堆和栈的区别
    sql执行顺序
    cookie session
    栈和队列
    c# 单例模式
  • 原文地址:https://www.cnblogs.com/hanc/p/3685978.html
Copyright © 2011-2022 走看看