D
deko
The method I want to run when my (Windows Forms app) form loads is an event
triggered by a radio button selection:
private void optColors_CheckedChanged(object sender,
EventArgs e)
But when the form is loading, there is no sender - so the below code fails:
RadioButton opt = (RadioButton)sender; //exception
if (opt.Checked)
{
string strOpt = opt.Name;
setCbo(strOpt);
}
What I need to do is somehow check if the sender is there, and if not, set
strOpt to a default value - something like this:
if (sender) //pseudo code
{
RadioButton opt = (RadioButton)sender;
}
else
{
//code to run on Form Load only
RadioButton opt = this.optColors;
}
if (opt.Checked)
{
string strOpt = opt.Name;
setCbo(strOpt);
}
How do I check for a valid sender? Do I check for EventArgs e instead?
Thanks in advance.
triggered by a radio button selection:
private void optColors_CheckedChanged(object sender,
EventArgs e)
But when the form is loading, there is no sender - so the below code fails:
RadioButton opt = (RadioButton)sender; //exception
if (opt.Checked)
{
string strOpt = opt.Name;
setCbo(strOpt);
}
What I need to do is somehow check if the sender is there, and if not, set
strOpt to a default value - something like this:
if (sender) //pseudo code
{
RadioButton opt = (RadioButton)sender;
}
else
{
//code to run on Form Load only
RadioButton opt = this.optColors;
}
if (opt.Checked)
{
string strOpt = opt.Name;
setCbo(strOpt);
}
How do I check for a valid sender? Do I check for EventArgs e instead?
Thanks in advance.