RadLabelElement RadRotator center

4 posts, 0 answers
  1. Developer Developer
    Developer Developer avatar
    34 posts
    Member since:
    Sep 2005

    Posted 17 Sep 2010 Link to this post

    I'm trying to center, both vertically and horizontally, a RadLabelElement within a RadRotator.  Does anyone know how this can be done?  Below is my initial try.

    RadLabelElement label = new RadLabelElement();
    label.Text = slide.Text;
    label.AutoSize = true;
    label.AutoSizeMode = RadAutoSizeMode.FitToAvailableSize;
    label.Alignment = ContentAlignment.MiddleCenter;
    label.StringAlignment = StringAlignment.Center;

    radRotator1.Items.Add(label);

    Any help would be greatly appreciated.  Thank you!
  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 23 Sep 2010 Link to this post

    Hello,

    Thank you for writing.

    In order to create and position a RadLabelElement in the Middle of RadRotator, please consider the following code snippet:
    public Form1()
    {
        new RadControlSpyForm().Show();
        InitializeComponent();
        PopulateRotator();
        
        label.Text = "label";
        label.StretchHorizontally = false;
        label.StretchVertically = false;
        CalcLabelLocation();
        radRotator1.RotatorElement.Children.Add(label);
        
        radRotator1.SizeChanged += new EventHandler(radRotator1_SizeChanged);
         
        radRotator1.Start();
    }
     
    void radRotator1_SizeChanged(object sender, EventArgs e)
    {
        CalcLabelLocation();
    }
     
    private void CalcLabelLocation()
    {
       int x = radRotator1.Location.X + radRotator1.Width / 2 - label.Size.Width /2;
       int y = radRotator1.Location.Y + radRotator1.Height / 2 - label.Size.Height/2;
       label.Location= new Point(x, y);
    }

    I hope you find this information helpful. If there is anything else I can assist you with, do not hesitate to contact me.

    Best wishes,
    Stefan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mahmoud
    Mahmoud avatar
    8 posts
    Member since:
    Mar 2011

    Posted 30 Apr 2013 Link to this post

    Hello Stefan,

    I was not able to figure out what Label is, can you attach us a complete code that does the above?

    Thanks.
    -Mahmoud
  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 03 May 2013 Link to this post

    Hello Mahmoud,

    "label" is RadLabelElement. Attached to this post you can find the requested sample. I hope it helps.
     
    Kind regards,
    Stefan
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top