Member 2458467 wrote:
I use the label control to debug the program instead of the Debug.Print("..."), I think the label control doesn't affect as you say.
Actually, it does work as I say, and it WILL lie to you when you have the UI thread tied up doing other things instead of letting it process the message pump so forms and controls can repaint themselves. Don't believe me? Start a new Windows form project and drop a label and a button on the form. Double click the button to create an event handler and drop the following code into the button handler:
for (int i = 1; i < 20000000; i++)
label1.Text = i.ToString();
Run it and click the button. Notice the label doesn't update? Also, you can't move the form around the screen either. It's doing this because you've got the UI thread tied up doing a long-running operation. It's can't process messages, like WM_PAINT, until that operation completes.
Member 2458467 wrote:
you say: "i never use the value of the Random so it's never being painted anywhere." What do I use to generate random numbers ?
You use Random to generate the values, but you're not understanding how Random works. When you create a new instance of Random and do not supply it with a seed value, it will use the current timer value. Do this multiple times in a row quick enough, and each one of the Random instances will return the exact same value! Create a single class-level instance of Random and you can use it throughout the rest of your class code and not have to worry about consecutive instances returning the same values.
public class Form1 : Form
{
private Random RNG = new Random();
.
.
.
private void SomeMethod()
{
...
int x = RNG.Next(10000);
...
}
}
In your code, you're getting the next random value and putting it in a variable, but then you never use that value in your paint code!
Member 2458467 wrote:
you say: "Form_Paint is a bit much for this. I'd create a Control specifically for the purpose ..." I haven't seen you create a Control specifically posted by you for everyone to see ?
Because I've got my own code to write that nobody is going to write for me and I'm not in the business of writing other peoples code for them. But, yeah, I wrote