maples

maples

  • NA
  • 1
  • 0

Custom MenuItem

Feb 5 2005 9:51 AM
Created simple class derived from MenuItem public class SauronMenuItem : System.Windows.Forms.MenuItem, IMenuItem { .... public SauronMenuItem(string Name, string Text, Image image, EventHandler onClick, Shortcut shortcut) : base(Text, onClick, shortcut) { OwnerDraw = false; _Name = Name; _Image = image; } protected override void OnMeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) { base.OnMeasureItem(e); //temporrally fixedvalues e.ItemHeight = 32; e.ItemWidth = 75; } protected override void OnDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { base.OnDrawItem(e); DrawText(e); } private void DrawText(System.Windows.Forms.DrawItemEventArgs e) { RectangleF TextRectF = new RectangleF(e.Bounds.X + 32, e.Bounds.Top, e.Bounds.Width - 48, e.Bounds.Height); ... e.Graphics.DrawString(Text, MenuFont, TextBrush, TextRectF, sf); } } When I try show ContextMenu then I get error "Out Of Memory". It happen after then method MenuItem.OnMeasureItem of last MenuItem called in ContextMenu. Same error happen if I add handlers to MeasureItem and DrawItem without override apropriate methods. Where is a bug? I hat i forgot did?

Answers (1)