简体   繁体   中英

Issue with form_load

I am trying to make certain labels buttons etc be visible on load up however, when I click off the form and back on to it the form_load code activates again. Its as if it was an onClick event instead of load.

I am completely new to coding so this will probably be something extremely simple

Many Thanks

private void formCanvas_Load(object sender, EventArgs e)
    {
        lblUsed.Visible = false;
        lblScore.Visible = false;
        lblUsedLetters.Visible = false;
        lblGuessWord.Visible = false;
        lblUserChoice.Visible = false;
        lblWord.Visible = true;
        txtUserLetter.Visible = false;
        txtUserWord.Visible = true;
        btnSubmitWord.Visible = true;
        btnSubmitLetter.Visible = false;
        lblLives.Visible = false;
        btnExit.Visible = false;
        btnRestart.Visible = false;
    }

you should put the code on the constructor of the formCanvas class

public formCanvas()
{
    InitializeComponent();
    lblUsed.Visible = false;
    lblScore.Visible = false;
    lblUsedLetters.Visible = false;
    lblGuessWord.Visible = false;
    lblUserChoice.Visible = false;
    lblWord.Visible = true;
    txtUserLetter.Visible = false;
    txtUserWord.Visible = true;
    btnSubmitWord.Visible = true;
    btnSubmitLetter.Visible = false;
    lblLives.Visible = false;
    btnExit.Visible = false;
    btnRestart.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