ContextMenuStrip text alignment C#

瘦欲@ 提交于 2019-12-13 02:15:18

问题


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.



来源:https://stackoverflow.com/questions/4397655/contextmenustrip-text-alignment-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!