There are no those graphical primitives as objects in
System.Windows.Forms
. You can create them based on the graphic rendering methods provided by the class
System.Drawing.Graphics
. Please see:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[
^].
You can render graphics using this class on any
Control
, including
Form
. You need to override the virtual method
System.Windows.Forms.Control.OnPaint
or handle the event
System.Windows.Forms.Control.Paint
and use the instance of
System.Drawing.Graphics
passed to this method or to your event handler as a parameter:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx[
^].
Please see my past answers for further advice:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^],
capture the drawing on a panel[
^],
Drawing Lines between mdi child forms[
^],
How to speed up my vb.net application?[
^],
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
How do I clear a panel from old drawing[
^].
See also this one, explaining how it's mapped to raw Windows API:
Zoom image in C# .net mouse wheel[
^],
MFC Drawed lines is disappeared[
^].
[EDIT]
Member 10267665 wrote:
It's different, because i can't assign an event on it for example, i need a line that can raise events when i click on it.
You have to handle click and other input events on the control where you render you lines or other elements. This is the control on which you handle the event
Paint
or override the method
OnPaint
.
In case of click handling, you will need to override the virtual method
System.Windows.Forms.Control.OnClick
or handle the event
System.Windows.Forms.Control.Click
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onclick.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.click.aspx[
^].
But then, the hard part starts: you would need to calculate some acceptable
vicinity of the line points which you would use as a "hot area" where the click is associated with your line object. In you handler of the click, you will have to determine if the click coordinates hit the area of this vicinity (so called "hit test") and, depending on that criterion, proceed with line-related handling, or handle some other graphical object, or ignore the event. Some mathematics is involved.
—SA