0

I'm new to C# and I need this function for a program im working on for school. I need to make a new window pop up when i click a button, not a message box though like a forms window, one that i can design with text boxes and buttons. What is on the new pop up window depends on the previous window but i can figure that out.

Also I need a way to close the previous window once the new one appears

Here's my code:`

// This makes sure only one box is checked   
private void MulCB_CheckedChanged(object sender, EventArgs e)
    {
        if( MulCB.Checked == true)
        {
            DivCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void DivCB_CheckedChanged(object sender, EventArgs e)
    {
        if (DivCB.Checked == true)
        {
            MulCB.Checked = false;
            AddCB.Checked = false;
            SubCB.Checked = false;
        }
    }

    private void AddCB_CheckedChanged(object sender, EventArgs e)
    {
        if (AddCB.Checked == true)
        {
            DivCB.Checked = false;
            SubCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void SubCB_CheckedChanged(object sender, EventArgs e)
    {
        if (SubCB.Checked == true)
        {
            DivCB.Checked = false;
            AddCB.Checked = false;
            MulCB.Checked = false;
        }
    }

    private void oneDCB_CheckedChanged(object sender, EventArgs e)
    {
        if(oneDCB.Checked == true)
        {
            twoDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void twoDCB_CheckedChanged(object sender, EventArgs e)
    {
        if ( twoDCB.Checked == true)
        {
            oneDCB.Checked = false;
            threeDCB.Checked = false;
        }
    }

    private void threeDCB_CheckedChanged(object sender, EventArgs e)
    {
        if (threeDCB.Checked == true)
        {
            oneDCB.Checked = false;
            twoDCB.Checked = false;
        }
    }
    // ends here
    // Button operation
    private void button8_Click(object sender, EventArgs e)
    {
        var form = new Form();
    }
}

} `

Thanks a lot! Sal

The project is im supposed to make a quizzing program for kids. They should be able to choose 1 operation and the amount of digits the numbers will have. It then has to out put 10 random questions according to the selection made by the kid, then once they have completed the quiz, it should display their results and which questions they got wrong.

Heres the welcome windows form

Sal
  • 59
  • 1
  • 1
  • 7
  • We need to see some code to understand what you are talking about; a WinForm window? WPF? UWP? ASP.NET? If this is your first program you need to get a book or tutorial; we can't do that for you. – Dour High Arch May 07 '17 at 16:26

1 Answers1

1

Assuming that the design of the window doesn't have to be completely dynamic, you can design it in Visual Studio (I'm assuming you did so with the first one). Then you can pass the results to the window. Like:

// Note: Form2 ist the name of your designed From
Form2 myform = new Form2();
this.Hide();
//You could pass the question settings like this
// 1 is for multiplication, 2 for division,3 for addition, 4 for substraction
myform.operation=1;
myform.digits=2
myform.Show();

And in the code of Form2:

namespace Yournamespace {  
    public partial class Form2: Form {
        //Add these two lines about here
        public static int operation;
        public static int digits;

        public Form2() {  
            InitializeComponent();  
        }  
    }  
}  

Then you can use the variables in Form2 and fill in the textbox or other elements you might design.

Also: You cloud use radio buttons instead of checkboxes as you then won't have you worry about unchecking the other checkboxes.

rudib
  • 227
  • 1
  • 10
  • Okay, thanks! I'm a little confused on how to transfer the operation and digits data between the two forms though. I'm still a beginner at c#, and from my google search i should use something called _events and delegates_ which looks pretty complicated. Any suggestions? – Sal May 07 '17 at 18:50
  • My secomd code example shows the code of the form that will be opened. There you have two variables as an example. You are modifying them from the first form(first code example) and you can access them in the new form. You shouln't need more than that. – rudib May 07 '17 at 18:55
  • I tried to implement it now, but it doesnt seem to work. I sure I'm the one who made the mistake, but this is important for the program to work. Do you know any videos or places i can learn what that code does? Copy pasting it didnt work. This is a little more advanced than what I'm used to, thats why im confused. – Sal May 07 '17 at 20:21
  • Copy pasting probably won't work its an example. You might have to adapt a few things. Maybe update your question with the code of the second form and also make sure that the code of the first form is up to date. And then comment so that I can get a notification. I hope its not particularly urgent. – rudib May 07 '17 at 20:25
  • I'v opened another post because the topic of this one is solved, and you're helping with a different problem at this point. Iv pasted the code and rewritten the explination over there now that im no longer frustrated at my stupidity like I was when i wrote this post. Here's the link http://stackoverflow.com/questions/43836526/passing-data-between-form1-and-form2-in-c-sharp – Sal May 07 '17 at 20:47