When running the code below, labels in the form are supposed to show the values of vx
and vy
via labels xVelV
and yVelV
. Unfortunately, both labels are unresponsive during the while
loop. However, as the program exits the loop, the values are then updated.
I've tried the same code by defining the vx
& vy
as properties with get
& set
methods (like, the set
method setting the value of vx
and xVelV.text
concurrently), but still no change.
Can anybody figure out what I'm doing wrong?
note: there is a g
defined outside the while loop (like Graphics g = panel.CreateGraphics();
) which is then used to draw rectangles inside the while block.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace fff {
class FormMain : Form {
// ... some code before
private Label xVelL = new Label();
private Label yVelL = new Label();
// ... some code after
public FormMain() {
// ... some code here
this.Controls.Add(xVelV);
this.Controls.Add(yVelV);
// ... some code here
}
public void RunG() {
// ... some code here
double x = 400.0, y = 050.0, xn, yn, vx, vy, ax, ay;
// ... some code here
bool massOut = false;
while (!massOut) {
// ... some code here
vx += ax;
vy += ay;
// ****** bug is here below !!! ******
this.xVelV.Text = vx.ToString();
this.yVelV.Text = vy.ToString();
// ****** bug is here above !!! ******
xn = x + vx;
yn = y + vy;
if (xn < 0 || xn > width || yn < 0 || yn > height) {
massOut = true;
}
else {
// ... some code here
x = xn;
y = yn;
// ... some code here
}
}
}
}
}