Winform中怎样设置ContextMenuStrip右键菜单的选项ToolStripMenuItem添加照
<h1>场景</h1><p>怎样在Winform步调中添加鼠标右键时使子选项表现图片。</p>
<p></p>
<p><img/></p>
<p>注:</p>
<p>博客主页: <br /><a href="https://blog.csdn.net/badao_liumang_qizhi">https://blog.csdn.net/badao_liumang_qizhi
</a><br />关注公众号 <br />霸道的步调猿 <br />获取编程相干电子书、教程推送与免费下载。 </p>
<h1>实现</h1>
<p>新建Winform步调,在Properties下的Resources下添加照片资源。</p>
<p></p>
<p> </p>
<p> </p>
<p>然后在窗体中拖拽一个Button,在Button的点击变乱中 </p>
//声明鼠标右键菜单
System.Windows.Forms.ContextMenuStrip ctxMenu = new System.Windows.Forms.ContextMenuStrip();
//设置右键子选项
ToolStripMenuItem mnuDelete = new ToolStripMenuItem();
//设置子选项的文本
mnuDelete.Text = "删除";
//设置子选项的照片
mnuDelete.Image = Properties.Resources.delete;
//将子选项添加到右键菜单
ctxMenu.Items.Add(mnuDelete);
//获取Button按钮
Button button = sender as Button;
//使右键菜单表现并设置表现位置
ctxMenu.Show(button, new Point(0, 0));
页:
[1]