Until the progressbar value reaches 100 do not close the window

Asked

Viewed 106 times

0

Before you start, it’s not really a virus, it’s a game. I wish that while the progressibar does not reach 100% could not close the window by clicking the button and a popup appears saying that it can not close here is the code:

private void button1_Click(object sender, EventArgs e)
{
    if (progressBar1.Value != 100)
    {
        this.Hide();
    }
    else if (progressBar1.Value > 100)
    {
        MessageBox.Show("You need to wait the virus download");
    }
}
  • You need the form Onclose event. I recently answered this question on Sopt.

  • progressBar1.Value > 100????

  • what is wrong?

  • It’s the other way around... Read this as se o valor da progressbar for MAIOR que 100.

  • Thanks for the help but it is not solved yet

  • Yes, young man. That was just a comment. The answer is down there.

  • I have already found a solution thanks to those who tried to help me

  • What was the solution? I was curious :)

  • I made sure that when the bar reached 100% the button to close the window appeared

Show 4 more comments

2 answers

1


  • is not going wrong on the part of (progressBar < 100)

  • @Pekira Tell us what the error/problem is, otherwise the author of the answer won’t be able to help you...

  • still not giving the visual studio accuses that the code is wrong

  • @Pekira Yes, but what does "Visual Studio say", young man? Help us help you...

  • opperator < cannot be Applied to Operators of type "progressBar" and "int"

  • Ready, young man. I edited the answer. You should have noticed that, don’t you think?

  • Save young people! I only saw now that my answer had not placed the Value property. But I did not worry so much at the time of the answer. The idea was to exemplify the Onformclosing method.

Show 2 more comments

0

Shura16’s answer is absolutely correct. The problem you encounter when compiling its answer is in the name of your progressibar. From what I’ve seen, your progressbar is named "progressBar1"

Try to copy the answer below:

protected override void OnFormClosing(FormClosingEventArgs e) 
{
    base.OnFormClosing(e);
    if (progressBar1.Value < 100) 
    {
        MessageBox.Show("Mensagem de alerta, não feche ainda!");
        e.Cancel = true;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.