Context menu with icons in c#

  • Thread starter Thread starter Anushya
  • Start date Start date
A

Anushya

Hi
How to create a context menu with icons??
I know there is no straight way of doing it.And i have the code
downloaded for vb.net. does anybody have code written in c#??
Anushya
 
Anushya said:
Hi
How to create a context menu with icons??

* Buy a professional UI framework.
* Use an open source implementation.
I know there is no straight way of doing it.And i have the code

So what?
downloaded for vb.net. does anybody have code written in c#??

Well, there are surely C# sample around, too.

And yes, I DO have the code written in C# (actually for the whole
Infragistics suite), but no, I can not give it to you - illegal.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
 
Why don't you try your hand at it? Make the menu items owner drawn and draw
the menu item yourself... It's not that difficult. You will need to
sub-class the menu-item and over-ride the OnDrawItem method on the menu
item.

Something like this:

using System.Windows.Form;
using System.Drawing;

public class MyMenuItem : MenuItem
{
private Image itemImage;

public MyMenuItem() : base ()
{
this.OwnerDraw = true;
}

/// Gets/sets the menu item's image
public Image
{
get
{
return itemImage;
}

set
{
itemImage = value;
}
}

protected override void OnDrawItem(DrawItemEventArgs e)
{
// Draw your item here
// DrawItemEventArgs provides you with the font, the
// back color, the fore color, the text, the state of the control
// the graphics canvas, etc... (all that you ever need to draw the
// control.

base.OnDrawItem(e);
}
}

-vJ
 
Back
Top