Hi
Does anybody know how we can align the text in the ContextMenuStrip (in WinForms) to the center?
thanks!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Implement custom ToolStripRenderer
(use one of 2 standard to minimize code):
public sealed class CustomRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
if(e.Item.IsOnDropDown)
{
e.TextFormat |= TextFormatFlags.HorizontalCenter;
}
base.OnRenderItemText(e);
}
}
And use it:
ToolStripManager.Renderer = new CustomRenderer();
Note though that this is not standard Windows GUI menu item layout which users expect.