473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating GroupBox with Radio Buttons from enum using reflection

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
Jun 27 '08 #1
4 6503
On Fri, 11 Apr 2008 17:55:06 GMT, "Gugale at Lincoln"
<gu**************@gmail.comwrote:
>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
It doesn't work if groubbox.AutoSize = True? If the groupbox is too
large make sure AutoSizeMode is set to GrowAndShrink.
Jun 27 '08 #2
On Fri, 11 Apr 2008 10:55:06 -0700, Gugale at Lincoln
<gu**************@gmail.comwrote:
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.
You need to set the AutoSize property of all of your relevant containers
-- GroupBox, TableLayoutPanel, and possibly the FlowLayoutPanel and the
containing Form as well -- to "true". Once you've done that, it should
work fine.

The GroupBox won't know to resize unless the TableLayoutPanel also
resizes. If your form is large enough always, then the GroupBox's parents
should be fine, but if not, they need to also be set to resize by setting
their AutoSize property to "true".

Pete
Jun 27 '08 #3
No it doesn't. It just shrinks to a dot. I think it is because I am using
TableLayoutPanel inside the group box. But I have no other options.
"Jack Jackson" <jj******@cinnovations.netwrote in message
news:bp********************************@4ax.com...
On Fri, 11 Apr 2008 17:55:06 GMT, "Gugale at Lincoln"
<gu**************@gmail.comwrote:
>>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

It doesn't work if groubbox.AutoSize = True? If the groupbox is too
large make sure AutoSizeMode is set to GrowAndShrink.

Jun 27 '08 #4
It worked. Thanks!

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Fri, 11 Apr 2008 10:55:06 -0700, Gugale at Lincoln
<gu**************@gmail.comwrote:
>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.

You need to set the AutoSize property of all of your relevant
ontainers -- GroupBox, TableLayoutPanel, and possibly the FlowLayoutPanel
and the containing Form as well -- to "true". Once you've done that, it
should work fine.

The GroupBox won't know to resize unless the TableLayoutPanel also
resizes. If your form is large enough always, then the GroupBox's parents
should be fine, but if not, they need to also be set to resize by setting
their AutoSize property to "true".

Pete

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mr.Clean | last post by:
I am trying to mimic a Windows GroupBox control using fieldset, label and radio buttons. The problem lies in that I can not correctly do the radio buttons relative to the groupbox and the label...
1
by: Agnes | last post by:
How can I bind the groupbox ?? My groupbox got 2 radio buttons . and my table's field is sex (F/M) I need to show the radio button either F or M. Anyone know how to do ?? Thanks
2
by: Rich | last post by:
Hello, If I place a groupbox control (gb1) on a form and add 2 radion buttons where rad1 represents a value of 1 of rad2 a value of 2 --- when I click on rad1 I want a messagebox to show the...
8
by: johnmmcparland | last post by:
Hi all, my program is trying to add group boxes with radio buttons at run time. While at one point it was able to draw the group boxes without the radio buttons, now it encounters problems just...
5
by: sam | last post by:
Hi all, I am dynamically creating a table rows and inerting radio buttons which are also dynamically created. Everything works fine in Firefox as expected. But I am not able to select radio...
2
by: K Forester | last post by:
Hi, I am a complete beginner and need help with a form. There are 2 group boxes, each containing 3 radio buttons on my form. I'd like to write a subroutine in a module that checks to be sure that...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, GroupBox1 contains 3 radiobuttons. Is there a builtin way - a Container property - in the groupbox control to determine which radiobutton is checked - if any? I did not see anything...
3
by: Sin Jeong-hun | last post by:
Suppose there are 4 radion buttons on the form. There's no groupbox or panel to seperate them. By default, the 4 radio buttons are mutually exclusive. Is it possible to group them into two groups?...
1
by: Lazairus | last post by:
simply how do you set enums in a database using coorsoponding radio button from a html form now i have a table client_membership in mysql with the membership_type enum('six','one') i...
4
by: Gugale at Lincoln | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.