I am trying to create a method for a timer event that takes 3 arguments. I have had a look at similar questions and tried to implement the solutions shown but the solution do not work in my case
GraphDrawingTimer.Elapsed += new ElapsedEventHandler(GraphPainter);
GraphDrawingTimer.Interval = 350;
GraphDrawingTimer.Enabled = true;
Above is the timer initialization
static void GraphPainter(object sender, ElapsedEventArgs e)
{
//Show_Graph(c);
}
thats method that will be called once the timer fires.
I want to add a PaintEventArgs c extra argument to draw a graph. I was using
private void tabPage2_Paint(object sender, PaintEventArgs e)
method but buttons do not get refreshed on my tabpage, thats why I want to create my own graph drawing method that will refresh every 350 milli-second. I have tried
GraphDrawingTimer.Elapsed += (object sender, ElapsedEventArgs e) => { GraphPainter(sender, e, c); };
GraphDrawingTimer.Interval = 350;
GraphDrawingTimer.Enabled = true;
.....
static void GraphPainter(object sender, ElapsedEventArgs e, PaintEventArgs c)
{
Show_Graph(c);
}
but that does not work. I get the error "The name 'c' does not exist in the current context". I also tried
PaintEventArgs c;
GraphDrawingTimer.Elapsed += (object sender, ElapsedEventArgs e)=> { GraphPainter(sender, e, c); };
GraphDrawingTimer.Interval = 350;
GraphDrawingTimer.Enabled = true;
.....
static void GraphPainter(object sender, ElapsedEventArgs e, PaintEventArgs c)
{
Show_Graph(c);
}
I get the following error
Error CS0165 Use of unassigned local variable 'c'
Which indeed makes sense since I'm not assigning any value to it - so how to assign a value to that PaintEventArgs c
to pass correct parameter of the Paint event? Or maybe there should be some other approach to invoke Paint event?