RadDropDownButton Item Layout

3 posts, 0 answers
  1. Allen
    Allen avatar
    14 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2013 Link to this post

    Hello,

    this bugs me for hours. i can't seem to arrange controls added through RadMenuItem, please see attached screenshot.

    here is the code i am using:

    RadMenuItem Item = new RadMenuItem();
    RadButtonElement Btn1 = new RadButtonElement();
    RadButtonElement Btn2 = new RadButtonElement();
    Item.Text = Dates[i].ToString();
    Btn1.DisplayStyle = Telerik.WinControls.DisplayStyle.Image;
    Btn1.ImageAlignment = ContentAlignment.MiddleCenter;
    Btn1.Image = Properties.Resources.edit;
    Btn1.AutoSize = false;
    Btn1.Size = new System.Drawing.Size(18, 18);
    Item.Children[2].Children[0].Children[1].Children.Add(Btn1);
     
    Btn2.Image = Properties.Resources.delete;
    Btn2.DisplayStyle = Telerik.WinControls.DisplayStyle.Image;
    Btn2.ImageAlignment = ContentAlignment.MiddleCenter;
    Btn2.AutoSize = false;
    Btn2.Size = new System.Drawing.Size(18, 18);
    Item.Children[2].Children[0].Children[1].Children.Add(Btn2);
     
    DateList.Items.Add(Item);

    i tried to set the autosize property to false and set a custom size, but to no avail.

    i am doing something wrong but what is it?

    Thanks!
  2. Allen
    Allen avatar
    14 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2013 Link to this post

    what i am trying to do is to align the text and buttons horizontally.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 19 Aug 2013 Link to this post

    Hello Allen,

    Thank you for writing.

    The best way for to achieve the the desired alignment is to create a custom MenuItem like the following one:
    public class MyRadMenuItem : RadMenuItem
    {
        private StackLayoutElement stackLayout;
        private RadButtonElement firstButton;
        private RadButtonElement secondButton;
        private LightVisualElement textElement;
     
        public string Text
        {
            get
            {
                return this.textElement.Text;
            }
            set
            {
                this.textElement.Text = value;
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
     
            this.stackLayout = new StackLayoutElement();
            this.stackLayout.Padding = new System.Windows.Forms.Padding(3);
            this.stackLayout.FitInAvailableSize = true;
            this.Children.Add(this.stackLayout);
     
            this.firstButton = new RadButtonElement();
            this.firstButton.DisplayStyle = Telerik.WinControls.DisplayStyle.Image;
            this.firstButton.Image = Resources.Edit;       
            this.firstButton.StretchHorizontally = false;
     
     
            this.secondButton = new RadButtonElement();
            this.secondButton.DisplayStyle = Telerik.WinControls.DisplayStyle.Image;
            this.secondButton.Image = Resources.Edit;
            this.secondButton.StretchHorizontally = false;
                
            this.textElement = new LightVisualElement();
            
            this.stackLayout.Children.Add(this.firstButton);
            this.stackLayout.Children.Add(this.secondButton);
            this.stackLayout.Children.Add(this.textElement);           
        }
    }

    Now you can create and add the item like this:
    MyRadMenuItem Item = new MyRadMenuItem();
     
    Item.Text = DateTime.Now.ToString();
     
    radDropDownButton1.Items.Add(Item);

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Dimitar
    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 >>
Back to Top