private void menuSubItemContextQYes_DrawItem(object sender, DrawItemEventArgs e) { Rectangle rcImage = e.Bounds; Image image = Image.FromFile(Application.StartupPath + @"\Icons\DeleteIcon.jpg"); rcImage.Width = image.Width/8; rcImage.Height = image.Height/8; e.Graphics.DrawImage(image, rcImage); MenuItem mi = (MenuItem)sender; Font menuFont = SystemInformation.MenuFont; SolidBrush menuBrush = new SolidBrush(SystemColors.MenuText); StringFormat strfmt = new StringFormat(); strfmt.LineAlignment = System.Drawing.StringAlignment.Near; Rectangle rcText = e.Bounds; rcText.X += rcImage.Width; e.Graphics.DrawString(mi.Text, menuFont, menuBrush, e.Bounds.Left - image.Width/8, e.Bounds.Bottom + ((e.Bounds.Height - menuFont.Height) / 2), strfmt); } private void menuSubItemContextQYes_MeasureItem(object sender, MeasureItemEventArgs e) { MenuItem mi = (MenuItem)sender; Font menuFont = SystemInformation.MenuFont; StringFormat strfmt = new StringFormat(); strfmt.LineAlignment = System.Drawing.StringAlignment.Near; SizeF sizef = e.Graphics.MeasureString(mi.Text, menuFont, 1000, strfmt); Image image = Image.FromFile(Application.StartupPath + @"\Icons\DeleteIcon.jpg"); e.ItemWidth = (int)Math.Ceiling(sizef.Width) + image.Width / 8; e.ItemHeight = (int)Math.Ceiling(sizef.Height) + image.Height / 8; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)