I use the OnPaint (c#) event to draw something in my form. I want to get the value of a variable during the OnPaint process. But I cant get it during, only before or after the OnPaint process...
In fact, the variable is like a counter that I want to get to increase the value of a ProgressBar.
I tried adding a Thread, a Timer and "ValueChanged" events, I still can't get the value. The code is quite long (it's for generating a HeatMap from some data).
I increase the value in some for loops during the event, and I call the OnPaint event by the "Invalidate()" function.
I hope to be clear without pasting my code (it's very long) ! Thanks.
With the code this is better : (Simplified)
public partial class HeatPainter : UserControl
{
public long _progress = 0; //My counter
public HeatPainter()
{
InitializeComponent();
}
public void DrawHeatMap(List<List<int>> Items, decimal Value, int MaxStacks, int Factor, string FileName)
{
if (_allowPaint) //If the control is ready to process
{
timer1.Start();
_progress = 0;
_allowPaint = false;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
for (int Pass = _factor; Pass >= 0; Pass--)
{
//Some draw stuff
//...
_progress++;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Console.WriteLine(_progress);
}
}