Hi, all...
I wish to call upon the DrawLinesPointF class to draw an array of points for me after I click on a button with design name button1. Upon compilation of my code, there is no error. However, when executed, and I clicked on the button, the following exception error occured:
An unhandled exception of type 'System.InvalidCastException' occurred in DrawingLines_Testing.exe
Additional information: Specified cast is not valid.
And the following line was highlighted:
DrawLinesPointF(sender, (PaintEventArgs) e);
Below is part of my code. Is there any problems with my definitions of the classes? Why do I have the problem with calling the class DrawLinesPointF? What do I have or lack?
private void DrawLinesPointF(object sender, PaintEventArgs e)
{
// Create pen.
Pen pen = new Pen(Color.Black, 3);
// Create array of points that define lines to draw.
PointF[] points =
{
new PointF( 10.0F, 10.0F),
new PointF( 10.0F, 100.0F),
new PointF(200.0F, 50.0F),
new PointF(250.0F, 300.0F)
};
//Draw lines to screen.
e.Graphics.DrawLines(pen, points);
}
private void button1_Click(object sender, System.EventArgs e)
{
Graphics g = button1.CreateGraphics();
// Creates a pen that draws in red.
Pen myPen1 = new Pen(Color.Red, 3);
g.DrawLine(myPen1, 1, 1, 200, 200);
DrawLinesPointF(sender, (PaintEventArgs) e);
}