0

我在工具条菜单控件中成功插入了一个项目。但我无法重新排列项目,如下所示:-

例如:- 目前项目已添加到工具条菜单中,如下所示:-

aa bb cc dd
ee ff gg hh

但我想要这样:-

aa ee
bb ff
cc gg
dd hh

我的代码是:-

private void CreateEnterpriseHierarchy(ToolStripMenuItem selectToolStripMenuItem)
    {
        try
        {
            ToolStripMenuItem entToolStripMenuItem = new ToolStripMenuItem();
            var enterprise = CurrentUserContext.ECPTree.Where(x => x.ImageIndex == 0).FirstOrDefault();
            if (enterprise != null)
            {
                entToolStripMenuItem.Tag = enterprise;
                entToolStripMenuItem.ToolTipText = entToolStripMenuItem.Name = entToolStripMenuItem.Text = enterprise.Name;
                //entToolStripMenuItem.Enabled = enterprise.IsNodeEnabled;
                //newToolStripMenuItem.Image = 
                entToolStripMenuItem.Image = this.imgListMenu.Images[0];
                CreateCompanyList(entToolStripMenuItem, enterprise);
            }
            else
            {
                entToolStripMenuItem.Text = "---------";
            }

            // To open Hierarchy of Enterprise - Companies and Properties with Multiple Columns

            ToolStripDropDown menu = new ToolStripDropDown();
            ToolStripItem[] items = new ToolStripItem[entToolStripMenuItem.DropDown.Items.Count];
            entToolStripMenuItem.DropDown.Items.CopyTo(items, 0);

            // Transfer the items into the drop-down menu.
            foreach (ToolStripItem item in items)
            {
                if (!(item is ToolStripSeparator)) menu.Items.Add(item);
            }

            // Adjust the layout of the new menu.
            menu.LayoutStyle = ToolStripLayoutStyle.Table;
            ((TableLayoutSettings)menu.LayoutSettings).ColumnCount = 6;

            // Attach it to the menu.
            entToolStripMenuItem.DropDown = menu;

            selectToolStripMenuItem.DropDownItems.Add(entToolStripMenuItem);
        }
        catch (Exception ex)
        {
            CusException cex = new CusException(ex);
            cex.Show(MessageBoxIcon.Error);
        }
    }

和方法 CreateCompanyList:-

void CreateCompanyList(ToolStripMenuItem selectedMenuItem, SCTreeView Enterprise)
    {
        try
        {
            ToolStripMenuItem enterpiseMenuItem = new ToolStripMenuItem();
            enterpiseMenuItem.Text = selectedMenuItem.Text;
            enterpiseMenuItem.Tag = selectedMenuItem.Tag;
            enterpiseMenuItem.Name = enterpiseMenuItem.Text = selectedMenuItem.Name;
            enterpiseMenuItem.Enabled = Enterprise.IsNodeEnabled;
            enterpiseMenuItem.ImageIndex = 0;
            enterpiseMenuItem.Image = this.imgListMenu.Images[0];
            enterpiseMenuItem.Click += new EventHandler(DisplaySelectedLevel);
            selectedMenuItem.DropDownItems.Add(enterpiseMenuItem);
            selectedMenuItem.DropDownItems.Add(new ToolStripSeparator());
            foreach (var item in CurrentUserContext.ECPTree)
            {
                if (item.ImageIndex == 1)
                {
                    ToolStripMenuItem companyMenuItem = new ToolStripMenuItem();
                    companyMenuItem.Tag = item;
                    companyMenuItem.Name = companyMenuItem.Text = item.Name;
                    // companyMenuItem.Enabled = item.IsNodeEnabled;
                    var lstProperties = CurrentUserContext.ECPTree.Where(x => x.ParentID == item.ID).ToList();
                    if (lstProperties.Count == 0)
                    {
                        companyMenuItem.Click += new EventHandler(DisplaySelectedLevel);
                    }
                    companyMenuItem.ImageIndex = item.ImageIndex;
                    companyMenuItem.Image = this.imgListMenu.Images[1];
                    selectedMenuItem.DropDownItems.Add(companyMenuItem);

                    CreatePropertyList(item, companyMenuItem);
                }
            }
            if (selectedMenuItem.DropDown.Height > 500)
            {
                selectedMenuItem.DropDown.AutoSize = true;
                selectedMenuItem.DropDown.Height = 500;
            }
            selectedMenuItem.DropDownDirection = ToolStripDropDownDirection.Default;
        }
        catch (Exception ex)
        {
            CusException cex = new CusException(ex);
            cex.Show(MessageBoxIcon.Error);
        }
    }

有什么方法可以实现所需的布局样式?

任何帮助或想法表示赞赏。

4

1 回答 1

0

标准的 .Net 菜单栏有点乱,尤其是在垂直显示方面。

将这些值应用于您的主菜单栏属性:

  • 文本方向:Vertical90
  • 布局样式:VerticalStackWithOverflow
  • 码头:左

这将使您的菜单栏比您预期的要大,但它依赖于它的 items width。当您要添加菜单时,请记住指定其宽度。

于 2013-10-18T09:12:20.600 回答