-2

I have a timer in My win app.

The timer interval is 3 seconds and deletes one item from listbox.

Here is the code:

private void timer3_Tick(object sender, EventArgs e)
{
    timer3.Enabled = false;
    if (listBox1.Items.Count > 0)
    {
        listBox1.Items.RemoveAt(0);
        progressBar1.Increment(1);
        groupBox2.Text = listBox1.Items.Count.ToString();
        timer3.Enabled = true;
    }
}

I want a message box to show that "listBox1 is clear" when listBox1.Items.Count == 0

thank you

Asad Ali
  • 684
  • 6
  • 17
Dr.zeus
  • 77
  • 1
  • 1
  • 9
  • possible duplicate of [Show a message box from a class in c#?](http://stackoverflow.com/questions/715206/show-a-message-box-from-a-class-in-c) – Austinh100 Jun 20 '14 at 16:04
  • 1
    I recommend disabling `timer3` before showing the `MessageBox` otherwise every 3 seconds a new `MessageBox` will popup. – Asad Ali Jun 20 '14 at 16:16

2 Answers2

1

Pretty simple, if it's not > 0, it must be == 0, so you can do an else { ... } and put a message box in.

private void timer3_Tick(object sender, EventArgs e)
{
    timer3.Enabled = false;
    if (listBox1.Items.Count > 0)
    {
        listBox1.Items.RemoveAt(0);
        progressBar1.Increment(1);
        groupBox2.Text = listBox1.Items.Count.ToString();
        timer3.Enabled = true;
    }
    else
    {
        MessageBox.Show("The list box is clear.");
    }
} 
qJake
  • 16,821
  • 17
  • 83
  • 135
0
private void timer3_Tick(object sender, EventArgs e)
{
timer3.Enabled = false;
if (listBox1.Items.Count > 0)
{
listBox1.Items.RemoveAt(0);
progressBar1.Increment(1);
groupBox2.Text = listBox1.Items.Count.ToString();
timer3.Enabled = true;
}
else {
messagebox.show("listBox1 is clear");
}
}
Dean.DePue
  • 1,013
  • 1
  • 21
  • 45