I am trying to make a simple Windows Form application that will show different options based on the values of preceding elements – for example I have four radio buttons at the top of the form, each one will show and hide elements various other elements within the form – essentially making several forms in one.
I have this set up in a large conditional statement (this is only a small portion, but it is all similar):
private void Payment_Load(object sender, EventArgs e)
{
if (rdoMultChoice.Checked)
{
lblGroupBox1_MC.Visible = true;
lblGroupBox1_FITB.Visible = false;
lblGroupBox1_TF.Visible = false;
// etc...
}
else if (rdoFillInBlank.Checked)
{
lblGroupBox1_MC.Visible = false;
lblGroupBox1_FITB.Visible = true;
lblGroupBox1_TF.Visible = false;
// etc...
}
The problem is, when I run the application the form completely ignores these statements and appears to just make all of my elements visible.
http://msdn.microsoft.com/en-us/library/754w18dd.aspx
This link is sort of similar to my needs. I tried to adapt it to my situation but it didn’t appear to work (can’t guarantee that I did it correctly…).
Seems like this should be a really simple thing to do but I am new to C# and only started using it this week – an assignment for a CS class. Just to rant, we are expected to develop “expertise” in 13 languages in 15 weeks! With very few resources provided by the university, so far the only expertise I have developed is in searching documentation and stack overflow! 🙂
First thing I would do is put a breakpoint in your code:
You want to know if
Payment_Loadis being executed.Next, after you’re certain it is being executed, check your code to see if there is anything that might be changing the label’s visibility. it could be another piece of code which is changing the
.Visiblesetting.