简体   繁体   中英

(C#)How do I, upon pressing a button, Make a new form window appear? One that i can drag other buttons and text boxes onto

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.

继承人欢迎窗口形式

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM