G
Gugale at Lincoln
Hi,
I am using reflection to read names from enum and creating radio buttons
inside a groupbox. Everything is working fine. However, I am not able to
adjust the size of the group box to fit the content. Is there a simple
solution to this problem? Parent of group box is FlowLayoutPanel which fills
the parent form.
string[] names = Enum.GetNames(pi.PropertyType); //pi is a PropertyInfo
object which represents a property of type enum.
GroupBox gbx = new GroupBox();
//gbx.AutoSize = true;
gbx.Name = "gbx" + pi.Name;
gbx.Text = pi.Name;
gbx.Padding = new Padding(2, 5, 2, 2);
panel.Controls.Add(gbx);
TableLayoutPanel tlp = new TableLayoutPanel();
tlp.ColumnCount = (int)Math.Floor(Math.Sqrt(names.Length));
tlp.Dock = DockStyle.Fill;
tlp.Padding = new Padding(1);
//int maxRBLength = 0;
foreach (string name in names)
{
RadioButton rb = new RadioButton();
rb.Name = "rb" + name;
rb.Text = name;
rb.AutoSize = true;
rb.Margin = new Padding(0, 0, 0, 0);
//if (rb.Width > maxRBLength) maxRBLength = rb.Width;
tlp.Controls.Add(rb);
}
gbx.Controls.Add(tlp);
Thanks
SG
I am using reflection to read names from enum and creating radio buttons
inside a groupbox. Everything is working fine. However, I am not able to
adjust the size of the group box to fit the content. Is there a simple
solution to this problem? Parent of group box is FlowLayoutPanel which fills
the parent form.
string[] names = Enum.GetNames(pi.PropertyType); //pi is a PropertyInfo
object which represents a property of type enum.
GroupBox gbx = new GroupBox();
//gbx.AutoSize = true;
gbx.Name = "gbx" + pi.Name;
gbx.Text = pi.Name;
gbx.Padding = new Padding(2, 5, 2, 2);
panel.Controls.Add(gbx);
TableLayoutPanel tlp = new TableLayoutPanel();
tlp.ColumnCount = (int)Math.Floor(Math.Sqrt(names.Length));
tlp.Dock = DockStyle.Fill;
tlp.Padding = new Padding(1);
//int maxRBLength = 0;
foreach (string name in names)
{
RadioButton rb = new RadioButton();
rb.Name = "rb" + name;
rb.Text = name;
rb.AutoSize = true;
rb.Margin = new Padding(0, 0, 0, 0);
//if (rb.Width > maxRBLength) maxRBLength = rb.Width;
tlp.Controls.Add(rb);
}
gbx.Controls.Add(tlp);
Thanks
SG