如何为 ContextMenuStrip 项目设置图像?我正在使用 C#。
问问题
6831 次
4 回答
1
尝试这个:
myContextMenuStrip.ShowImageMargin = true;
于 2011-11-02T20:30:36.407 回答
1
You're looking for the (drumroll...) Image
property!
于 2011-05-16T15:28:34.940 回答
1
您需要将ToolStripItem.DisplayStyle属性设置为Image然后设置image属性
这是来自 MSDN 的示例
- 从文件中获取图像
- 将样式设置为图像和文本
- 将图像与 MiddleLeft 对齐
- 设置iteme的名称
- 将文本对齐到 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);
于 2011-05-16T15:29:32.117 回答
0
Image
属性
DisplayStyle
必须设置为ImageAndText
OrImage
于 2011-05-16T15:30:40.460 回答