This is a migrated thread and some comments may be shown as answers.

Change RadFormTitleBarElement default context menu

2 Answers 107 Views
TitleBar
This is a migrated thread and some comments may be shown as answers.
Joaquín
Top achievements
Rank 2
Joaquín asked on 27 Sep 2020, 10:20 AM

Hi guys,

Is it possible to change the RadFormTitleBarElement default context menu (Minimize, Maximize, Restore, etc.) for a customized one? I have seen that RadTitleBar has a ContextMenuProperty property exposed, but I cannot find it in my RadForm embebed title bar.

Thank you very much.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Sep 2020, 12:17 PM

Hello, JoaquĆ­n,

I suppose that you want to replace the following context menu:

Indeed, RadTitleBar has a dedicated property for the context menu. However, RadForm internally uses a RadTitleBarElement and the context menu illustrated above comes from a core logic. You can replace the default context menu of the Operating System, by extending RadForm and overriding the WndProc method. If the message is WM_CONTEXTMENU, you should create and show your own context menu. 

  public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent(); 
        }

        public const int WM_CONTEXTMENU = 0x7b;
         

        protected override void WndProc(ref System.Windows.Forms.Message m)
        { 
            if (m.Msg == WM_CONTEXTMENU)
            {
                RadContextMenu menu = new RadContextMenu();

                RadMenuItem item = new RadMenuItem("Restore");
                item.Click += new EventHandler(item_Click);
                menu.Items.Add(item);

                RadMenuItem item1 = new RadMenuItem("Maximize");
                item1.Click += new EventHandler(item1_Click);
                menu.Items.Add(item1);

                RadMenuItem item2 = new RadMenuItem("Minimize");
                item2.Click += new EventHandler(item2_Click);
                menu.Items.Add(item2);

                menu.Show(this, PointToClient(Control.MousePosition));

                return;
            }

            base.WndProc(ref m);
        }

        void item1_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
        }

        void item_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

        void item2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
    }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Joaquín
Top achievements
Rank 2
answered on 30 Sep 2020, 09:21 AM
Thank you very much Dess. Your solution works just perfect!
Tags
TitleBar
Asked by
Joaquín
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Joaquín
Top achievements
Rank 2
Share this question
or