简体   繁体   中英

Making a new form window appear in c#

I'm trying to make a card game using Windows Application Forms.

The thing is that I don't know how to do the following- for example if i'd have 3 buttons - one of them named, for example, "Play" , if i'd click on it, it would open the actual game, but in the same window, it would only make the buttons dissapear, and when i'd click back, it would open the window with buttons again. I don't really know how to explain my problem better, hopefully someone can tell me how to do that.

You don't have to hide / show the buttons. What you can do instead is to make a new form with the cards on it. That Form will pop up after you click the play button.

private void PlayButton_Click(object sender, EventArgs e)
{
    // You other functionality goes here
    GameForm GF = new GameForm();
    GF.Show();
    //Or - try this and see the difference 
    GF.ShowDialog();
}

Good Luck!

In addition to Leez's answer, in your situation, you should think about using container controls rather than handling the visible states of individual controls.

You could put related controls in a Panel, GroupBox or TabControl and set the visible properties of those containers instead.

you can use Visible property of button to do that as follows.

    private void button1_Click(object sender, EventArgs e)
    {
        // You other functionality goes here
        button1.Visible = false;
    }

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