我正在尝试在手动设置高度为 60 的上下文菜单项中垂直对齐中心的文本。但是无论我尝试什么,文本始终位于顶部。同一项目中的图像将正确对齐,而无需我做任何事情。
我尝试了以下方法:
foreach (ToolStripItem item in ContextMenuStrip1.Items)
{
item.AutoSize = false;
item.Height = 60;
item.Width = maxWidth;
item.TextAlign = ContentAlignment.MiddleCenter;
}
并创建一个新的 customerRender 类:
public sealed class CustomRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
if (e.Item.IsOnDropDown)
{
e.TextFormat |= TextFormatFlags.VerticalCenter;
}
base.OnRenderItemText(e);
}
}
但是,这对我不起作用。文本垂直保持在项目的顶部。添加到这些项目之一的图像居中,箭头表示更多。
任何帮助都会很棒。艾丹