While the progressbar value does not reach 100 does not close the window

0

Before you start, it's not a virus, it's a game. I wish that while progressbar does not reach 100% could not close the window when clicking the button and popup appears to say that can not close is the code here:

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");
    }
}
    
asked by anonymous 25.07.2016 / 19:57

2 answers

1

You can use the OnFormClosing Event:

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

Source: link

    
25.07.2016 / 20:10
0

Shura's answer is absolutely correct. The problem you encounter when compiling his answer is in the name of your progressbar. From what I've seen, your progressbar is named "progressBar1"

Try copying 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;
    }
}
    
25.12.2016 / 18:17