RadRibbonGroup or Tab UserControl

2 posts, 1 answers
  1. Psibernetic
    Psibernetic avatar
    1 posts
    Member since:
    Jan 2013

    Posted 01 Oct 2013 Link to this post

    Hi I am trying to determine how I would need to go about encapsulating a Ribbon Tab so that it can be used in several different places, otherwise I will have to write some slightly unpleasant code for determining the context of the contextual tab and making the buttons interact accordingly.
  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 04 Oct 2013 Link to this post

    Hi Psiberbernetic,

    Thank you for contacting us.

    You can create a class which derives from RibbonTab with some predefined elements inside:
    public class MyRibbonTab : Telerik.WinControls.UI.RibbonTab
    {
        private RadRibbonBarGroup group;
        private RadButtonElement button;
        private string name;
     
        public MyRibbonTab(string name)
        {
            this.AccessibleDescription = name;
            this.AccessibleName = name;
            this.IsSelected = false;
            this.Name = name;
            this.Text = name;
            this.Visibility = ElementVisibility.Visible;
        }
     
        public RadRibbonBarGroup Group
        {
            get
            {
                return this.group;
            }
        }
     
        public RadButtonElement Button
        {
            get
            {
                return this.button;
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
     
            this.group = new RadRibbonBarGroup();
            this.group.AccessibleDescription = "Group";
            this.group.AccessibleName = "Group";
            this.group.Name = "Group";
            this.group.Text = "Group";
            this.group.Visibility = ElementVisibility.Visible;
     
            this.button = new RadButtonElement();
            this.button.AccessibleDescription ="Button";
            this.button.AccessibleName = "Button";
            this.button.Name = "Button";
            this.button.Text = "Button";
            this.button.Visibility = ElementVisibility.Visible;
            this.button.MinSize = new Size(100,50);
            this.button.InvalidateArrange(true);
     
            this.Items.Add(this.group);
            this.group.Items.Add(this.button);
     
            this.button.Click += button_Click;
        }
     
        void button_Click(object sender, EventArgs e)
        {
            RadMessageBox.Show("Click");
        }
    }

    You can add the tab as follows:
    for (int i = 0; i < 4; i++)
    {
        this.radRibbonBar1.CommandTabs.Add(new MyRibbonTab("Tab " + i));
    }

    I hope this helps.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top