Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
public class CustomMenuItem : ToolStripMenuItem
{
        protected override void OnPaint(PaintEventArgs e)
        {
            var rect = new RectangleF(1, 1, this.Size.Width-2, this.Size.Height-2);
            if (IsMouseHover == true)
            {
                using (var b = new SolidBrush(Color.FromArgb(49, 106, 197)))
                {
                    e.Graphics.FillRectangle(b, rect);
                }
            }
            else
            {
                using (var b = new SolidBrush(Color.FromArgb(255, 255, 255)))
                {
                    e.Graphics.FillRectangle(b, rect);
                }
            }

            CheckState state = this.CheckState;
            if (state == System.Windows.Forms.CheckState.Checked)
            {
                if ((CheckMarkDisplayStyle == CheckMarkDisplayStyle.RadioButton))
                {
                    DrawCircle(e.Graphics);
                }
                else if ((CheckMarkDisplayStyle == CheckMarkDisplayStyle.CheckBox))
                {
                    DrawChecked(e.Graphics);
                }

                this.Checked = true;

                finalCheckedMenuItem = this;
            }

            SolidBrush drawBrush = new SolidBrush(Color.Black);
            System.Drawing.Size txtSize = TextRenderer.MeasureText(this.Text, this.Font);

            PointF drawPoint = new PointF(10, (this.Height - txtSize.Height) / 2);

            StringFormat sf = new StringFormat();
            //sf.Alignment = StringAlignment.Center;
            //sf.LineAlignment = StringAlignment.Center;
            sf.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;  
            e.Graphics.DrawString(this.Text.ToString(), this.Font, drawBrush, drawPoint,sf);
        }
}



when i inheritance ToolStripMenuItem,and beacause of some reasons,i don't written base.OnPaint(e); my require is set the shortcutkeys and show nomal in toolstripmenuitem.text ,but now it invalid. how can i solove this question?

improve my question:
Shortcutkeys property is invalid,and not show in the toolstripmenuitem.Text.
Posted
Updated 12-Apr-15 19:30pm
v4
Comments
Sergey Alexandrovich Kryukov 13-Apr-15 1:22am    
Not clear. What is "invalid"? what do you mean by that? what are you trying to show?..
—SA
Sinisa Hajnal 13-Apr-15 2:02am    
I'll ask the same, what do you mean by "invalid"? Do you get an error? It doesn't work...what?
xuyunhai 13-Apr-15 2:54am    
the property Shortcutkeys doesn't work. it's invalid property
Sinisa Hajnal 13-Apr-15 3:04am    
How did you define it? Does it work if you replace your custom item with normal menu item?
xuyunhai 13-Apr-15 3:24am    
I use my custom menuitem, and just set the shortcutkeys property as usually,but it dosn't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900