开发者

ContextMenuStrip text alignment C#

开发者 https://www.devze.com 2023-01-29 11:19 出处:网络
Hi Does anybody kn开发者_运维知识库ow how we can align the text in the ContextMenuStrip (in WinForms) to the center?

Hi

Does anybody kn开发者_运维知识库ow how we can align the text in the ContextMenuStrip (in WinForms) to the center? thanks!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号