I want to transfer the angle of a line to be drawn via a class AnglePaintEvent Args which is derived from PaintEventArgs class.
public class AnglePaintEventArgs : PaintEventArgs
{
int angle;
public AnglePaintEventArgs(Graphics graphic, Rectangle rectangle, int Angle) : base(graphic, rectangle)
{
angle = Angle;
}
}
The panel’s eventhandler only accepts functions that have the argument PaintEventArgs but not AnglePaintEventArgs. I was not able to cast the args. Several tries:
public Form1()
{
InitializeComponent();
//tried this
this.panel1.Paint += new PaintEventHandler(AnglePaintEventArgs);
//tried that
this.panel1.Paint += new AnglePaintEventArgs;
this.panel1.Paint += panel1_Paint;
}
does not work neither.
private void panel1_Paint(object sender,AnglePaintEventArgs e)
Is it necessary to derive a new panel object class? Does it help to declare a new delagate with the AnglePaintEventArgs and hook it to the panel object?
This strikes me as a bit of an X-Y Problem because even if you were to succeed in injecting an angle into a custom
PaintEventArgsclass a line and draw it, it's likely to be erased on the next refresh unless you're persisting it in a document of some kind. Same goes for aTag. To draw on any control, call itsRefresh()method and it will respond by firing thePaintmessage and providing aGraphicsblank canvas to draw on. Given that the effect of having anangleproperty in the event argument or a tag would be so ephemeral, it's not a good fit there.Consider making a
Lineclass with theAngleproperty that goes in aList<object>that can hold the various shapes you want to draw. You can continue to add more lines to the document, then callpictureBox.Refreshwhenever there is a new shape to draw.Extensions