Fill space for a control within a panel in c #


I continue with my project in Winforms C # and I have many problems since I only know WPF and Silverlight, which is very similar.

In WPF if I put, in XAML :


Without setting the height and width the control is adjusted to the size of the parent, how is it done in WinForms?

At the moment I have a generic panel, the size I want.

Since there is no XAML in projects

asked by Fer garcia 31.12.2015 в 16:35

2 answers


Use the% control% of the Son Control, you have to adjust it to Dock :

What is the central box?

This will adjust the size of the parent element, ignoring the height and size of the control, and if the window resizes it will also change this control, as long as its parent can adjust.

answered by 31.12.2015 / 16:36

You can do so:

const int MARGEN = 2;
. . .
miControl.Location.X = MARGEN;
miControl.Location.Y = MARGEN;
miControl.Size.Width = miPanel.Width - (MARGEN*2);
miControl.Size.Height = miPanel.Height - (MARGEN*2);
answered by 31.12.2015 в 16:42