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

RadDropDownButton Item Layout

2 Answers 120 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Allen
Top achievements
Rank 1
Allen asked on 15 Aug 2013, 03:23 AM
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 Answers, 1 is accepted

Sort by
0
Allen
Top achievements
Rank 1
answered on 15 Aug 2013, 04:24 AM
what i am trying to do is to align the text and buttons horizontally.
0
Dimitar
Telerik team
answered on 19 Aug 2013, 02:04 PM
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 >>
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Allen
Top achievements
Rank 1
Answers by
Allen
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or