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

RadLabel size is zero without a parent

1 Answer 63 Views
Label
This is a migrated thread and some comments may be shown as answers.
Gary C
Top achievements
Rank 1
Gary C asked on 09 Dec 2009, 06:01 PM
Hello,

I'm using the Dec 3rd version of the WinForms components. After upgrading some of our forms don't look right. What I determined was a RadLabel created dynamically has a size of (0, 0) until it is assigned to a container. Is there a way to know the size of the RadLabel before it has a parent? Our current logic relies on the size of the labels to build the container form so it is broken because of this change.

Here is some sample code to show the issue:

RadLabel rl = new RadLabel(); 
rl.Text = This is a test; 
rl.Location = new Point(20, 20); 
 
// rl.Size is (0,0) at this point 
 
this.Controls.Add(rl); 
 
// now rl.Size is correctly showing (67, 14) in this test 


Thanks,

-Gary

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 11 Dec 2009, 04:35 PM
Hi Gary C,

The new behavior is a part of the Telerik Presentation Framework optimizations introduced in Q3 2009. Still, if you want your RadLabel to get a valid size before it is added to a parent container, you need to call the LoadElementTree method:

public Form1()
{
    InitializeComponent();
  
    RadLabel rl = new RadLabel();  
    rl.Text = "This is a test";  
    rl.Location = new Point(20, 20);
    rl.LoadElementTree();
    // at this points the size is (67, 14)  
}

I hope this helps. If you have additional questions, feel free to contact me.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Label
Asked by
Gary C
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or