Drop down control on Document Window Tab

8 posts, 0 answers
  1. Tejas
    Tejas avatar
    2 posts
    Member since:
    Aug 2012

    Posted 12 Mar 2012 Link to this post

    Hello,
    I was wondering if there is a way to add a drop-down menu on the tab of a document window in the dock. It would be exactly same as the little down pointing arrow next to the close button on the right-hand side which lists the active documents. Just that I would want it on each tab next to that tab's close button.

    Thanks!
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 15 Mar 2012 Link to this post

    Hello Tejas,

    Thank you for your question.

    Currently, such behavior cannot be achieved due to the internal implementation of RadDock. However, such functionality seems reasonable and therefore I have logged this as a feature request in our Public Issue Tracking System. Here you can find the PITS entry. You can subscribe to it and track it for changes. You can also vote for it to increase its priority.

    Your Telerik points have been updated for the feature request.

    Should you have any further questions, do not hesitate to ask.

    Regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Tejas
    Tejas avatar
    2 posts
    Member since:
    Aug 2012

    Posted 15 Mar 2012 Link to this post

    Thank you for the response.

    A follow up question: Can we add/remove items in the context menu for the docwindow tabstrip? While not the ideal solution, it would suffice for now.

    Otherwise, would the dropdown menu functionality work using through some other Radcontrol such as RadPageView? Basically, we have tab specific options that need to be accessed.

    Any suggestions would be welcome.
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 19 Mar 2012 Link to this post

    Hello Tejas,

    Yes, you can customize the context menus of RadDock. The following code snippet demonstrates how:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.radDock1.GetService<ContextMenuService>().ContextMenuDisplaying += new ContextMenuDisplayingEventHandler(Form32_ContextMenuDisplaying);
        }
     
        void Form32_ContextMenuDisplaying(object sender, ContextMenuDisplayingEventArgs e)
        {
            if (e.MenuType == ContextMenuType.ActiveWindowList)
            {
                e.MenuItems.Add(new RadMenuItem("Custom overflow item"));
            }
            else if(e.MenuType == ContextMenuType.DockWindow)
            {
                if (e.DockWindow is DocumentWindow)
                {
                    e.MenuItems.Add(new RadMenuItem("Action specific to " + e.DockWindow.TabStripItem.Text));
                }
            }
        }
    }

    More information about the ContextMenuService can be found in this help article.

    As to inserting a dropdown button inside RadPageView tabs, this is also possible to achieve. The following code snippet demonstrates this:
    public Form1()
    {
        InitializeComponent();
        this.radPageView1.ItemCreating += new EventHandler<RadPageViewItemCreatingEventArgs>(radPageView1_ItemCreating);
        this.radPageView1.Pages.Add(new RadPageViewPage() { Text = "Page 1" });
        this.radPageView1.Pages.Add(new RadPageViewPage() { Text = "Page 2" });
        this.radPageView1.Pages.Add(new RadPageViewPage() { Text = "Page 3" });
    }
     
    void radPageView1_ItemCreating(object sender, RadPageViewItemCreatingEventArgs e)
    {
        e.Item = new MyPageViewItem();
    }
     
    public class MyPageViewItem : RadPageViewStripItem
    {
        CommandBarDropDownButton button;
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
            this.button = new CommandBarDropDownButton();
            this.button.Items.Add(new RadMenuItem("item1"));
            this.button.Items.Add(new RadMenuItem("item2"));
            this.button.Items.Add(new RadMenuItem("item3"));
            this.button.MinSize = new Size(16,16);
            this.button.Image = null;
            this.Children.Add(button);
        }
     
        protected override SizeF MeasureOverride(SizeF availableSize)
        {
            SizeF size = base.MeasureOverride(availableSize);
            size.Width += button.DesiredSize.Width;
            size.Height = Math.Max(size.Height, button.DesiredSize.Height);
            return size;
        }
     
        protected override void ArrangeChildren(SizeF available)
        {
            base.ArrangeChildren(available);
            button.Arrange(new RectangleF(available.Width - button.DesiredSize.Width, 0, button.DesiredSize.Width, available.Height));
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadPageViewStripItem);
            }
        }
    }

    I hope you find this information useful. Feel free to write back if you need further assistance.

    All the best,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. John
    John avatar
    3 posts
    Member since:
    Aug 2010

    Posted 18 Feb 2013 Link to this post

    Hi -
    I am able to add a context menu item in the ContextMenuDisplaying event as you have specified in this post, however, the ContextMenuService ContextMenuItemClicked event does not fire when I click the newly added item. 

    I am using v.2012.1.321.40 of RadControls for Winforms.

    Any help would be appreciated.

    Thanks!
    John
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 21 Feb 2013 Link to this post

    Hi John,

    Since those are not default items, you have to subscribe to the custom menu items Click events:
    void Form32_ContextMenuDisplaying(object sender, ContextMenuDisplayingEventArgs e)
    {
        if (e.MenuType == ContextMenuType.ActiveWindowList)
        {
            RadMenuItem customOverflowItem = new RadMenuItem("Custom overflow item");
            customOverflowItem.Click += customOverflowItem_Click;
            e.MenuItems.Add(customOverflowItem);
        }
        else if (e.MenuType == ContextMenuType.DockWindow)
        {
            if (e.DockWindow is DocumentWindow)
            {
                RadMenuItem actionSpecificTo = new RadMenuItem("Action specific to " + e.DockWindow.TabStripItem.Text);
                actionSpecificTo.Click +=actionSpecificTo_Click;
                e.MenuItems.Add(actionSpecificTo);
            }
        }
    }
     
    void actionSpecificTo_Click(object sender, EventArgs e)
    {
        //do smth
    }
     
    void customOverflowItem_Click(object sender, EventArgs e)
    {
        //do smth
    }

    I hope this helps.
     
    Kind regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  8. John
    John avatar
    3 posts
    Member since:
    Aug 2010

    Posted 21 Feb 2013 Link to this post

    OK, great, thanks for the reply.

    That works as you described, however, I was hoping to be able to use the ContextMenuClickEventArgs to use the e.DockWindow property, which I will accomplish by setting a class level variable in the ContextMenuDisplaying handler.

    Are there plans to add menu customization to the ContextMenuService in  the future?

  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 26 Feb 2013 Link to this post

    Hi Tejas,

    Thank you for writing back.

    Currently, the ContextMenuItemClicked event is fired for the default items only and you have to handle the custom ones. I would suggest that you save the desired window in the Tag of the menu item and use it in the Click event handler:
    actionSpecificTo.Tag = e.DockWindow;
     
    ///
    void actionSpecificTo_Click(object sender, EventArgs e)
    {
        RadMenuItem item = (RadMenuItem)sender;
        DockWindow dockWin = (DockWindow)item.Tag;
        //here you have the DockWindow
    }

    Let us know if you need anything else.

    Greetings,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready