【问题标题】:How can I hide the mdiChild icon in an UltraToolbar when the mdiChild is maximized?最大化子项时,如何在 Ultra 工具栏中隐藏 mdi 子项图标?
【发布时间】:2013-05-31 21:10:02
【问题描述】:

我可以将图标设置为 1x1 或透明图标,但我不喜欢这种解决方案,因为用户仍然可以点击它。

如果是 mdiParents mainMenuStrip,我可以这样做:

private void mainMenuStrip_ItemEventHandler(Object sender, ToolStripItemEventArgs e)
        {
            if (e.Item.Text == "")
            {
                e.Item.Visible = false;//This will hide any toolstrip items that do not have text... ex. the SystemMenu.
            }
        }

但是 UltraToolbarsManager.Toolbars 没有这个事件。

将 mdiChild 的 ShowIcon 设置为 false 仅在 mdiChild 表单未最大化时有效。

我还尝试重载 mdiChild SizeChanged 事件并循环浏览工具以查看是否可以找到要隐藏的事件,但这也不起作用:

private void MdiChild_SizeChanged(object sender, EventArgs e)
        {
            Form theForm = sender as Form;
            switch (theForm.WindowState)
            {
                case FormWindowState.Maximized:
                    theForm.Icon = Icon.FromHandle(Properties.Resources.blank.GetHicon());
                        foreach (UltraToolbar ut in UltraToolbarsManager1.Toolbars)
                        {
                            if (ut.IsMainMenuBar)
                            {
                                foreach (ToolBase tb in ut.Tools)
                                {
                                    //This collection does not contain the one I want to hide.

                                    // maybe?
                                    if (tb is MdiMergePlaceholderTool)
                                    {
                                        tb.SharedProps.Visible = false;
                                    }
                                }
                            }
                        }
                    break;
            }
        }

UltraToolbarsManagerUltraToolbar 似乎没有任何我可以处理的事件来尝试删除正在合并到工具栏中的内容...

这是我也有的确切问题..但没有回答: http://www.infragistics.com/community/forums/t/33396.aspx

我认为这是另一个帖子建议的更新链接,但修改 100 个表单以像这样继承对我来说不是一个选项: http://help.infragistics.com/Help/NetAdvantage/WinForms/2013.1/CLR4.0/html/Win_Creation_Filter.html

几种可能性: - 在 OnItemAdded 事件中隐藏项目。 - 从 UltraToolbar 中删除图标.. 可能在 OnMerge 事件中。 - 如果图标无法隐藏/删除,则取消上下文菜单的事件。 - 获得对图标项目的引用的某种方式会很好。

提前感谢您的任何回复。

【问题讨论】:

    标签: c# icons infragistics mdichild


    【解决方案1】:

    查看提供的信息,我假设您使用的是我们默认的 UltraToolbarManager 模式,因为如果您使用的是 Ribbon 模式,那么您可以通过 MDIChild 表单的属性 ShowIcon 隐藏系统图标。 那时我们没有实现这样的功能(除了功能区模式)来隐藏你的图标或系统菜单,所以你有两种可能的选择来解决这个任务。 选项 1:您可以使用 CreationFilter。例如:

    public Form1()
    {
        InitializeComponent();
        ultraToolbarsManager1.CreationFilter = new HideIcon();
    }
    
    
    class HideIcon : IUIElementCreationFilter
    {
        public void AfterCreateChildElements(UIElement parent)
        {
    
        }
    
        public bool BeforeCreateChildElements(UIElement parent)
        {
            if (parent is PopupToolUIElement)
            {
                parent.Parent.ChildElements.Remove(parent);
            }
            return false;
        }
    }
    

    您可以在我们的论坛帖子中找到示例:http://www.infragistics.com/community/forums/t/33396.aspx

    如果您实施,另一种可能的方法是:

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    public static extern Int32 RemoveMenu(IntPtr hMenu, Int32 nPosition, Int32 wFlags);
    

    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
    public static extern bool DestroyMenu(IntPtr menu);
    

    通过这种方式,您可以在最大化您的 MDIChild 表单时破坏您的菜单,并在使用以下方法更改您的 MDIChild 表单的状态时再次创建上下文菜单:

    [DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern IntPtr CreatePopupMenu();
    

    我认为您解决此任务的最佳选择可能是使用 CreationFilter

    如果您有任何问题,请告诉我 问候

    【讨论】:

    • 谢谢!创建过滤器代码运行良好。它仍然缩进其他菜单项,就像图标在那里一样,但我可以处理。
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多