ToolStripMenuItem bigger vertical padding, or vertically centering text in a bigger ToolStripMenuItem
You can get the same effect using Margin
instead of Padding
which will keep the Text
of the ToolStripMenuItem
aligned.
The drawback is that this wont modify the size of the highlight rectangle when the item is selected so it can look a little strange if you increase a lot the height.
In addition to InBetween's answer, you can fix the highlight rectangle by using a custom renderer and adjusting its "TextRectangle" property. Here's some sample code that should help
var itemHeight = 36;
var verticalPadding = 36 - TextRenderer.MeasureText("A", _DisplayNameFont).Height / 2;
menu.Renderer = new MyRenderer { VerticalPadding = verticalPadding };
class MyRenderer : ToolStripSystemRenderer
{
public int VerticalPadding { get; set; }
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
if (null == e)
{ return; }
e.TextFormat &= ~TextFormatFlags.HidePrefix;
e.TextFormat |= TextFormatFlags.VerticalCenter;
var rect = e.TextRectangle;
rect.Offset(0, VerticalPadding);
e.TextRectangle = rect;
base.OnRenderItemText(e);
}
}