c# - 如何为 ContextMenuStrip 项设置图像?

标签 c# .net winforms contextmenustrip

如何为 ContextMenuStrip 项设置图像?我正在使用 C#。

最佳答案

您需要设置 ToolStripItem.DisplayStyle属性(property)给Image然后设置 image属性

这是来自 MSDN 的示例

  • 从文件中获取图像
  • 设置样式为图片和文字
  • 将图像对齐到 MiddleLeft
  • 设置主题名称
  • 设置文本对齐方式为MiddleRight
  • 设置文本
  • 并添加一个 Click 事件处理程序

示例

this.toolStripButton1.Image = Bitmap.FromFile("c:\\NewItem.bmp");
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText;
this.toolStripButton1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Text = "&New";
this.toolStripButton1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);

关于c# - 如何为 ContextMenuStrip 项设置图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6019600/

相关文章:

c# - 在不创建页面的新实例的情况下在同一 Window WPF 中切换 View

.net - 使用 LINQ 进行拓扑排序

.NET Core WebApi CSV文件解析并存储在数据库中

c# - 通过索引获取列表框项的值

winforms - 从两个组合框中选择特定的 Access 表单

c# - 在 SQL SERVER Reporting Services (SSRS) 中显示 rtf 数据

c# - 无法获取元素

.net - 使用 .Net 计算目录中的文件数

c# - XtraTreeList AutoNodeHeight

c# - Asp.net mvc Razor 将文本文件中的值填充到文本区域