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);
                }

Recommended Answers

All 11 Replies

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

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

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

While true
{

}Do()

Hope i helped,
Alex

What also works, strange as it may be:

for( ; ; ) //loop forever
{
    //code here
}

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.

the codes make my GUI turn no response.

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

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.