Resizing Controls that are contained in a docked Control

I

illegal.prime

I'm surprised that I'm only know discovering this problem, but I
suppose I've never needed to change the dimension that is opposite to
the docking of the control. That is, when I've docked a control to
Top, I've never needed to change its height and vice-versa. But, now I
would like to do this and I'm not sure what the "right way" is to
perform this.

Should I just add an extra container (panel, usercontrol, etc) around
the control whose dimension I want to change. For example, if I have a
UserControl whose width I would like to set manually and which happens
to be set to Dock to Top. Should I just house it in another
UserControl/Panel/Etc and then not Dock it in that container?

Thanks,
Novice

PS If my problem is not abundantly clear - create a windows
application, Add a Panel to your Form, then in the Contructor - put
this:
for (int i = 0;i < 50; i++)
{
Label label = new Label();
label.Dock = DockStyle.Top;
label.Text = "MyTextMyTextMyTextMyTextMyTextMyTextMyText" + i;
label.Width = 1000;
label.Height = 1000;
//label.Size = new Size(1000,300);
panel1.Controls.Add(label);
}

for (int i = 0;i < panel1.Controls.Count;i++)
{
Console.Out.WriteLine("control width: "+panel1.Controls.Width+"
control height: "+panel1.Controls.Height);
}

Then notice how the controls all get set to a height and width of 1000.
Then try changing the panel1 to be docked - either to Fill or just one
side and you'll see how the dimension changes you try to make will be
suppressed.
 
J

John B

I'm surprised that I'm only know discovering this problem, but I
suppose I've never needed to change the dimension that is opposite to
the docking of the control. That is, when I've docked a control to
Top, I've never needed to change its height and vice-versa. But, now I
would like to do this and I'm not sure what the "right way" is to
perform this.

Should I just add an extra container (panel, usercontrol, etc) around
the control whose dimension I want to change. For example, if I have a
UserControl whose width I would like to set manually and which happens
to be set to Dock to Top. Should I just house it in another
UserControl/Panel/Etc and then not Dock it in that container?

Thanks,
Novice

PS If my problem is not abundantly clear - create a windows
application, Add a Panel to your Form, then in the Contructor - put
this:
for (int i = 0;i < 50; i++)
{
Label label = new Label();
label.Dock = DockStyle.Top;
label.ba
label.Text = "MyTextMyTextMyTextMyTextMyTextMyTextMyText" + i;
label.Width = 1000;
label.Height = 1000;
//label.Size = new Size(1000,300);
panel1.Controls.Add(label);
}

for (int i = 0;i < panel1.Controls.Count;i++)
{
Console.Out.WriteLine("control width: "+panel1.Controls.Width+"
control height: "+panel1.Controls.Height);
}

Then notice how the controls all get set to a height and width of 1000.
Then try changing the panel1 to be docked - either to Fill or just one
side and you'll see how the dimension changes you try to make will be
suppressed.


I dont quite follow what the problem is here.

You are setting the dockstyle of the label to top which should (and
does) suppress any width changes except those triggered by the resize of
the parent (panel1).

The Height is able to be changed just fine (at least in my sample).

Bear in mind also the autosize property of the label is true by default.

Multiple top docked controls appear to be cascaded too.

If you need to have a 'docked' control that does not span the whole
width/height then use the anchor property instead.

JB
 
C

Cor Ligthert [MVP]

Hi,

If I understand you well, than have a look at the anchor properties.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top