Newbie problem with button click event arguments

  • Thread starter Thread starter jdf
  • Start date Start date
J

jdf

I'm new to C# and this question is very elementary. In the code below,
CreateGraph is a button click event handler and Form1_Paint creates a
graphics object and draws a few lines. When the user clicks the button
(handled by CreateGraph), the graph is to be drawn on the form. However, I
don't what arguments I should use in the Form1_Paint call from the Create
Graph button click event handler. Any help would be most appreciated.

private void CreateGraph(object sender, System.EventArgs e)

{

Form1_Paint(what goes here?);

}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
pe)

{

Graphics g = pe.Graphics;

Pen ThisPen = new Pen(Color.Black);

ThisPen.Width = 5;

g.DrawLine(ThisPen,5,5,20,30);

g.DrawLine(ThisPen,5,10,22,34);

g.DrawLine(ThisPen,5,15,31,40);

}

Thanks very much for any help.
 
When your Form needs to paint your "Form1_Paint" handler should get called.
There are a few different ways to cause a paint operation. One way is to
call the Invalidate method of the object to paint.

private void button1_Click(object sender, System.EventArgs e)
{
this.Invalidate();
}

In the code above, assuming that this is called from within the scope of a
Form, the Form will be asked to repaint.
 
Back
Top