473,467 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

group box

Hello,

1)I wanted to know if there is a way to determine the size of a group
box according to the number of radio buttons being added to it?

2)Is there a way to access to the radio buttons (in code) via the
group box control?

Thank U veru much!
Nov 16 '05 #1
5 11379
Hi Juli,

You can access any controls inside container controls like panels and
groupboxes.
Use the Controls property of the GroupBox to access its controls.

int n = 0;
foreach(Control c in MyGroupBox.Controls)
{
if(c is RadioButton)
n++;
}
MessageBox.Show("My GroupBox contains " + n + " RadioButtons.");

You can calculate the size based in the number of radiobuttons or access
the size of each control inside the GroupBox and add them together.

int h = 0;
int w = 0;
foreach(Control c in MyGroupBox.Controls)
{
if(c is RadioButton)
{
h += c.Size.Height;
w += c.Size.Width;
}
}

You can also set the Tag/Name property of the RadioButtons to identify
them further.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Hello,
I tried to do this:
foreach (Control c in this.groupBox1.Controls)
{
groupBox1.Size.Height=groupBox1.Size.Height+c.Heig ht;
}

but I keep getting compile error:
Cannot modify the return value of 'System.Windows.Forms.Control.Size'
because it is not a variable

How can I change this value?

Another question,
My controls inside the group box are radio buttons and I need to know
which one of them been selected,how do I do it via the group box?

Thanks a lot!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi,

You can't set the height or width individually, you need to set the full
size property.

foreach (Control c in this.groupBox1.Controls)
{
groupBox1.Size = new Size(groupBox1.Size.Width, groupBox1.Size.Height
+ c.Height);
}

As for your second question, you need to cast the control back to a
radiobutton.

foreach (Control c in this.groupBox1.Controls)
{
RadioButton rb = (RadioButton)c;
if(rb.Checked)
// do stuff
}

Note that if you have other controls than radiobuttons you will get an
exception.
In that case, test for a radiobutton using if(c is RadioButton).

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
First of all ,Thanks! but I still have a problem with the size I did:
if(c is RadioButton)
{
groupBox2.Size = new Size(groupBox2.Size.Width,
groupBox2.Size.Height
+ c.Height);

}

but it becomes too huge ,maybe there need to be a casting or something ?
Thank you!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Without having tested it, I'm assuming the groupBox have an initial
default size that you need to ignore. Try setting the initial size to 0 or
perhaps even better, store the height of the RadioButtons only and set
GroupBox size at the end.
int n = 0;
foreach(Control c in groupBox2.Controls)
{
if(c is RadioButton)
n += c.Height;
}

groupBox2.Size = new Size(groupBox2.Size.Width, n);
--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #6

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

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
7
by: Darin | last post by:
I have a report that sub-totals on a group, then grand-totals at the report footer. If there's only one group, the sub-total and grand total are redundant, so I only want to show one of them. I...
1
by: David Horowitz | last post by:
Hi folks. I need to create a report that has a Group Header that pulls certain data from the Detail section. It's something like this: +--Report---------------------------------------- |...
7
by: Sameh Ahmed | last post by:
Hello there IsInrole gives ya the means to check if the current or impersonated user belongs to a specific windows role or group. is there a way to do the same without using ADSI to check if...
2
by: jon|k | last post by:
hi all-- i need to do a transformation that removes duplicates (among other things). to accomplish that, i'm trying to use for-each-group, but it doesn't work. i need to select for duplicates by...
3
by: Sebastian | last post by:
Hello all I have a report where I have two nested groups. I know there are only three standard options for running sum: None, Over Group and Over All. I have a MyTextBox in detail section where...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.