Alan Spurlock Alan Spurlock - 1 month ago 9
C# Question

Adding control at runtime, not following panels padding properties

I am adding controls at run-time to my

Panel
, but the are not following the panels
Padding
property.

The
Label
below, just gets placed in the very top left of my panel. I have my panel at
20,20,20,20
in
Padding
, but it's still not working. Any ideas? Thanks!

//Thickness Combo Clicked\\
private void Thickness_Clicked(object sender, EventArgs e)
{
RadMenuItem item = sender as RadMenuItem;
switch (item.Text)
{
case "6":
RadLabel label = new RadLabel();
label.Text = "Test";
radPanel1.Controls.Add(label);
break;
case "20":
//
break;
}
}

Answer

Padding of Panel is just respected by those child controls which you have set their Dock property to a value different from None. In fact, as mentioned in documentations The Padding property of Panel is a more general realization of the DockPadding property of a ScrollableControl and the property property determines the border inside of this control for docked components.

So in above case which you added the Label without setting Dock property, the label and panel controls are working properly and your label will be shown at 0,0 location.

To solve the problem you need to set the Location manually or use a TableLayoutPanel instead.

Comments