Problem with system menu submenu when having a VisualStyle on a form

Posted by: mike on 23 November 2021, 1:46 am EST

  • Posted 23 November 2021, 1:46 am EST

    If I have a Visual Style on a winform - like this:

    this.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2010Black;

    then if I add a submenu to a system menu of the form, clicking on the item in the submenu closes the form!

    If there is no VisualStyle set, it works fine. Please tell me if there is some workaround…

    Here’s the code:

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool AppendMenu(IntPtr hMenu, int uFlags, int uIDNewItem, string lpNewItem);
        [DllImport("user32.dll")]
        public static extern IntPtr CreatePopupMenu();
    
        public const int MF_STRING = 0x00000000;
        public const int MF_POPUP = 0x00000010;
    
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Ribbon.Show();
            IntPtr hSysMenu = GetSystemMenu(this.Handle, false);
            AppendMenu(hSysMenu, MF_STRING, 0x10005, "another menu item");
            var hSubMenu = CreatePopupMenu();
            AppendMenu(hSubMenu, MF_STRING, 0x10010, "submenu");
            AppendMenu(hSysMenu, MF_POPUP, (int)hSubMenu, "submenu item");
        }
    
  • Posted 23 November 2021, 1:49 am EST

    I forgot to add to the above - you DO need to place a C1Ribbon on the form for the problem to show itself.

  • Posted 24 November 2021, 4:52 am EST

    Hi Mike,

    C1.Win.C1Ribbon.C1Ribbon is the legacy ribbon and control. We would suggest you upgrade to the new C1Ribbon for regular updates and fixes.

    We checked with the new ribbon and could observe the issue. We have escalated the issue to the dev team and will let you know when we have an update.

    [Internal Tracking ID: C1WIN-26173]

    As a workaround, you can override the WndProc method and then avoid closing the form when the submenu item is clicked. Please refer to the sample attached.

    Regards

    Avnish

    C1Ribbon_SystemMenu.zip

  • Posted 22 April 2022, 3:14 am EST

    Hi,

    This issue has been fixed in the latest 22v1 release. Please update to the latest release using the C1ControlPanel from https://www.grapecity.com/componentone/download.

    If you face any issues, let us know.

    Regards

    Avnish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels