How to adjust image for ContextMenuStrip elements?

How to set image for ContextMenuStrip elements? I am using C #.

+3
source share
4 answers

You need to set the ToolStripItem.DisplayStyle Image property , and then set the image property

Here is a sample from MSDN which

  • gets image from file
  • sets the style for image and text
  • aligns image to MiddleLeft
  • name itme
  • sets text alignment to MiddleRight
  • sets the text
  • and adds a Click event handler

Example

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);
+1
source

You are looking for a (drumroll ...)                   Imageproperty!

+1

:

myContextMenuStrip.ShowImageMargin = true;
+1

ImageThe property DisplayStylemust be set to ImageAndTextOrImage

0
source

All Articles