I'm looking for way to add an icon in a header of ContextMenuStripEx ..
is there any way to do it?
Thanx
Alessandro.
public class ContextMenuStripEx : ContextMenuStrip
{
public override Rectangle DisplayRectangle
{
get
{
Rectangle rc = base.DisplayRectangle;
rc.Y += TitleHeight;
return rc;
}
}
public override Size GetPreferredSize(Size proposedSize)
{
Size szResult = base.GetPreferredSize(proposedSize);
szResult.Height += TitleHeight;
return szResult;
}
internal int TitleHeight
{
get { return 25; }
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Image image = Image.FromFile(@"..\..\Images\ExitIcon.png");
e.Graphics.FillRectangle(new SolidBrush(Control.DefaultBackColor), 1, 1, this.Width - 2, TitleHeight);
Rectangle imgRect = new Rectangle(2, 2, 16, 16);
e.Graphics.DrawImage(image, imgRect);
Rectangle textRect = new Rectangle(imgRect.Width + 2, 2, this.Width, TitleHeight);
e.Graphics.DrawString(Text, this.Font, new SolidBrush(Color.Black), textRect);
}
} |
//Invoke Itemclicked event
private void ContextMenuStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ToolStripMenuItem menuItem;
menuItem = e.ClickedItem as ToolStripMenuItem;
//set forecolor for the selected MenuItem
menuItem.ForeColor = Color.Red;
}
|
Thanks for the reply,
but the suggested event is fired when the user selects the item,
I hope change the fore color whe i moving the menu.
I use this event to do action .
In addition the link for example is invalid.
Best Regard.
Alessandro.
I don't like this solution very much,
I would like to be able to work on a contextmenu event and not continuously add handlers
to objects that will be immediately destroyed
Have you a better solution?
Best Regards.
Alessandro.