I have a program and i want to make the increment keep adding on.

I added a while loop but its not working.

Anyone help ?

int Limit = 0; 
            if (e.Button == MouseButtons.Left)
            {

                ((PictureBox)sender).Left += (e.X - x);
                ((PictureBox)sender).Top += (e.Y - y);
                ((PictureBox)sender).BringToFront();
  
                int Qty = 0;
                while ( Qty <= Limit) { 
                
                Qty++;
                textBox1.Text = Convert.ToString(Qty);
                }

Edited 6 Years Ago by lishannx: n/a

for (int Qty = 0; Limit == 0; Qty++)
{
        textBox1.Text = Convert.ToString(Qty);
}

By using this code I am not responsible for your actions.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

A more simple way is to use the 'While' statement as follows:

While true
{

}Do()

Hope i helped,
Alex

Sorry all, it does not work at all.

It does not increment at all.

When the picturebox had been dragged, it will be counting from 1 to 2 then 3 and so on. but it does not work like that.

OK, I probably misunderstood your post.
Why are you setting Limit to 0 on line 1 of your original code?
Set it to 50 for instance, you will see that your while loop (on line 10)will count from one to fifty.(Very fast I think...)

while ( Qty >= Limit) {
    Qty++;
    textBox1.Text = Convert.ToString(Qty);
}

Note : it will cause exception once max value of int is reached.

Edited 6 Years Ago by alexlim17: n/a

the codes make my GUI turn no response.

and in such the quantity does not increment inside the textbox.

Edited 6 Years Ago by lishannx: n/a

>the codes make my GUI turn no response.

That's true. Take a look.

private void button1_Click(object sender, EventArgs e)
        {

            textBox1.Invoke(new Action<int,int>((a,b) => {
                while (a > b)
                {
                    textBox1.Text = a.ToString();
                    a--;
                    System.Threading.Thread.Sleep(70);
                    textBox1.Refresh();
                }
            
            }),20,1);
}

can i make the increment counter slower?
like drag one picturebox den plus 1.

>can i make the increment counter slower?

System.Threading.Thread.Sleep(1000); // 1000 millisecond

As in ,
i only wan the counter to add 1 when the picturebox is dragged.
Not when NO PICTUREBOX dragged, the counter will keep increasing.

This article has been dead for over six months. Start a new discussion instead.