J
johnmmcparland
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 getting the radiobuttons
out of the group box.
/// area where radio buttons added to groupbox
/// this code is wrapped in another loop creating group boxes
for (int j= 0; j < TactonManager.noTactons(); j++)
{
// create a radio button
RadioButton rb= new RadioButton();
rb.CreateControl();
Console.WriteLine("going to create a radio button");
rb= createRadioButton(j,yVal,tactonMids);
gb.Controls.Add(rb);
Console.WriteLine("created radio button {0} and added it to the
controls of the group box",j);
Console.WriteLine("rb location= {0}",rb.Location.ToString());
} // radio button for
// update the current bottom position before drawing next group box
bottomY= gb.Location.Y + gb.Size.Height;
grpBxs.Add(gb);
/// end of enclosing loop
// groupBoxes is a member of the class
groupBoxes= grpBxs;
/// area where radio buttons accessed from groupBox
int count = groupBoxes.Count;
Console.WriteLine("no group boxes= {0}",count);
// loop round group boxes
foreach (Object o in groupBoxes)
{
GroupBox g = (GroupBox)o;
Console.WriteLine("location of GroupBox=
{0}",g.Location.ToString());
int temp= g.Controls.Count;
this.Controls.Add(g);
Console.WriteLine("group boxes.controls= {0}",g.Controls.Count);
// loop round radiobuttons
int j = 0;
foreach (Control c in g.Controls)
{
Console.WriteLine("going to draw a radio button {0}",j);
Console.WriteLine("RadioButton location=
{0}",((RadioButton)c).Location);
this.Controls.Add((RadioButton)c);
j++;
}
/// <debug>
/// note: this only seems to try to draw radio buttons 0,2 (at
posns 45, 127)
/// it misses out those at 86 and 168, and still does with a normal
loop.
/// plus it doesn't actually draw them
/// </debug>
Console.WriteLine("exited the loop for the radio buttons");
}
it only finds two of my radio buttons (on the 3rd (index 2) I get an
error.
Below is all of the relevant output from the program and compiler
going to create a radio button
creating radio buttons
created radio button 0 and added it to the controls of the group box
rb location= {X=45,Y=287}
going to create a radio button
creating radio buttons
created radio button 1 and added it to the controls of the group box
rb location= {X=86,Y=287}
going to create a radio button
creating radio buttons
created radio button 2 and added it to the controls of the group box
rb location= {X=127,Y=287}
going to create a radio button
creating radio buttons
created radio button 3 and added it to the controls of the group box
rb location= {X=168,Y=287}
no group boxes= 1
location of GroupBox= {X=16,Y=267}
group boxes.controls= 4
going to draw a radio button 0
RadioButton location= {X=45,Y=287}
going to draw a radio button 1
RadioButton location= {X=127,Y=287}
going to draw a radio button 2
An unhandled exception of type 'System.NullReferenceException' occurred
in SimpleSimonTactile.exe
Additional information: Object reference not set to an instance of an
object.
The thread '<No Name>' (0xab8) has exited with code 0 (0x0).
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
at SimpleSimonTactile.UserGuessUI.drawSelectors() in c:\documents
and settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
345
at SimpleSimonTactile.UserGuessUI..ctor() in c:\documents and
settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
96
at SimpleSimonTactile.UserGuessUI.ShowForm() in c:\documents and
settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
396
as you may notice that while only two radio buttons are able to be
"drawn" (at x posns 45 and 127) those at posns 16 and 168 are missed
out. Why?
Please help
John
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 getting the radiobuttons
out of the group box.
/// area where radio buttons added to groupbox
/// this code is wrapped in another loop creating group boxes
for (int j= 0; j < TactonManager.noTactons(); j++)
{
// create a radio button
RadioButton rb= new RadioButton();
rb.CreateControl();
Console.WriteLine("going to create a radio button");
rb= createRadioButton(j,yVal,tactonMids);
gb.Controls.Add(rb);
Console.WriteLine("created radio button {0} and added it to the
controls of the group box",j);
Console.WriteLine("rb location= {0}",rb.Location.ToString());
} // radio button for
// update the current bottom position before drawing next group box
bottomY= gb.Location.Y + gb.Size.Height;
grpBxs.Add(gb);
/// end of enclosing loop
// groupBoxes is a member of the class
groupBoxes= grpBxs;
/// area where radio buttons accessed from groupBox
int count = groupBoxes.Count;
Console.WriteLine("no group boxes= {0}",count);
// loop round group boxes
foreach (Object o in groupBoxes)
{
GroupBox g = (GroupBox)o;
Console.WriteLine("location of GroupBox=
{0}",g.Location.ToString());
int temp= g.Controls.Count;
this.Controls.Add(g);
Console.WriteLine("group boxes.controls= {0}",g.Controls.Count);
// loop round radiobuttons
int j = 0;
foreach (Control c in g.Controls)
{
Console.WriteLine("going to draw a radio button {0}",j);
Console.WriteLine("RadioButton location=
{0}",((RadioButton)c).Location);
this.Controls.Add((RadioButton)c);
j++;
}
/// <debug>
/// note: this only seems to try to draw radio buttons 0,2 (at
posns 45, 127)
/// it misses out those at 86 and 168, and still does with a normal
loop.
/// plus it doesn't actually draw them
/// </debug>
Console.WriteLine("exited the loop for the radio buttons");
}
it only finds two of my radio buttons (on the 3rd (index 2) I get an
error.
Below is all of the relevant output from the program and compiler
going to create a radio button
creating radio buttons
created radio button 0 and added it to the controls of the group box
rb location= {X=45,Y=287}
going to create a radio button
creating radio buttons
created radio button 1 and added it to the controls of the group box
rb location= {X=86,Y=287}
going to create a radio button
creating radio buttons
created radio button 2 and added it to the controls of the group box
rb location= {X=127,Y=287}
going to create a radio button
creating radio buttons
created radio button 3 and added it to the controls of the group box
rb location= {X=168,Y=287}
no group boxes= 1
location of GroupBox= {X=16,Y=267}
group boxes.controls= 4
going to draw a radio button 0
RadioButton location= {X=45,Y=287}
going to draw a radio button 1
RadioButton location= {X=127,Y=287}
going to draw a radio button 2
An unhandled exception of type 'System.NullReferenceException' occurred
in SimpleSimonTactile.exe
Additional information: Object reference not set to an instance of an
object.
The thread '<No Name>' (0xab8) has exited with code 0 (0x0).
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
at SimpleSimonTactile.UserGuessUI.drawSelectors() in c:\documents
and settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
345
at SimpleSimonTactile.UserGuessUI..ctor() in c:\documents and
settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
96
at SimpleSimonTactile.UserGuessUI.ShowForm() in c:\documents and
settings\mcparlaj\my documents\degree course\4th
year\project\software\simplesimontactile\simplesimontactile\userguessui.cs:line
396
as you may notice that while only two radio buttons are able to be
"drawn" (at x posns 45 and 127) those at posns 16 and 168 are missed
out. Why?
Please help
John