多行文字菜单项 [英] multiline text menu item

查看:74
本文介绍了多行文字菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ContextMenuStrip和ToolStripMenuItem类创建菜单.我看不到如何创建多行文本菜单.

知道如何在winform中进行操作吗?

I am creating menu using ContextMenuStrip and ToolStripMenuItem classes. I do not see how to create multiline text menu.

Any idea how to do it in winform ?

推荐答案

我看不到在Visual Designer中输入它的方法
I see no way to enter it in Visual Designer, however
Menu1Item1.Text = "Menu 1 Line 1\nMenu 1 Line 2"


效果很好.

因此,您可以做的是在Visual Designer中输入一个特殊字符(例如#"),然后输入一些代码来修复文本.这需要递归,就像这样:


works just fine.

So what you could do is enter a special character (say ''#'') in Visual Designer, then have some code fixing the texts; this takes recursion, like so:

private void Form1_Load(object sender, EventArgs e) {
    foreach (ToolStripItem tsi in MainMenuStrip.Items) {
        fixToolStripMenuNewLines(tsi);
    }
}
private void fixToolStripMenuNewLines(ToolStripItem tsi) {
    log("tsi="+tsi.Text);
    ToolStripMenuItem tsmi=tsi as ToolStripMenuItem;
    if (tsmi!=null) {
        foreach (ToolStripItem tsi2 in tsmi.DropDownItems) {
            log("tsi2="+tsi2.Text);
            tsi2.Text=tsi2.Text.Replace("#", "\n");
            fixToolStripMenuNewLines(tsi2);
        }
    }
}




:)




:)


我还没有在C#中尝试过此方法,但是在VB中,可以通过对此进行编码而不是在设计人员中来实现.只需在文本中插入一个CRLF.您可以在表单加载事件中执行此操作.

例如

Menuitem1.text = "Menu 1 Line 1" & vbcrlf & "Menu 1 Line 2"
I haven''t tried this in C#, but in VB this can be achieved by coding this, rather than in the designer. simply insert a CRLF in the text. You could do this in the form load event.

e.g.

Menuitem1.text = "Menu 1 Line 1" & vbcrlf & "Menu 1 Line 2"


这篇关于多行文字菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆