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.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.