CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Custom MenuItem

Threaded View

  1. #1
    Join Date
    Dec 2004
    Posts
    7

    Unhappy Custom MenuItem

    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?
    Last edited by Umka; February 5th, 2005 at 10:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured