Home > other >  Windows Forms Labels not showing before continuing
Windows Forms Labels not showing before continuing

Time:06-13

I'm building a simple Forms project. The method that loads the data takes a while to run, so I want the window to show that it is loading. There are some Labels that I Hide when the Form loads and then Show when the data is loading. However, for some reason I can't figure out, my Labels do not Show. The Buttons Hide properly, but the Labels do not Show before the data starts loading. Why is this? How do I fix it? I am looking for the simplest solution possible, please and thanks.

private void loadExistingButton_Click(object sender, EventArgs e)
        {
            loadExistingButton.Hide();
            loadJsonButton.Hide();
            this.Size = new Size(375, 179);
            cardsLabel.Show();
            loadingLabel.Show();
            treeLabel.Show();
            formattedLabel.Show();

            loadFromExisting();
            MainForm mainForm = new MainForm(startNode);
            mainForm.FormClosed  = (s, args) => this.Close();
            this.Hide();
            mainForm.ShowDialog();
        }

        private void StartForm_Load(object sender, EventArgs e)
        {
            cardsLabel.Hide();
            loadingLabel.Hide();
            treeLabel.Hide();
            formattedLabel.Hide();
        }

CodePudding user response:

@Chetan 's suggestion is more suitable.

for example

//you can use this
cardsLabel.Visible = true;
//instead of
cardsLabel.Show();

//and you can use this
cardsLabel.Visible = false;
//instead of
cardsLabel.Hide();

CodePudding user response:

Changing to directly setting Visible did not solve the problem, however calling Refresh() after Show did solve the problem. Thank you @Jimi for the solution!

  • Related