How to: Draw a Line on a Windows Form
This example draws a line on a form. Typically, when you draw on a form, you handle the form’s Paint event and perform the drawing using the Graphics property of the PaintEventArgs, as shown in this example
Example
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
e.Graphics.DrawLine(pen, 20, 10, 300, 100);
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 0))
e.Graphics.DrawLine(pen, 20, 10, 300, 100)
Compiling the Code
The preceding example is designed for use with Windows Forms, and it requires PaintEventArgse
, which is a parameter of the Paint event handler.
Robust Programming
You should always call Dispose on any objects that consume system resources, such as Pen objects.
See also
Tehke meiega GitHubis koostööd
Selle sisu allika leiate GitHubist, kus saate ka probleeme luua ja läbi vaadata ning päringuid teha. Lisateavet leiate meie kaasautorite juhendist.
.NET Desktop feedback
Tagasiside
https://aka.ms/ContentUserFeedback.
Varsti tulekul: 2024. aasta jooksul tühistame GitHubi probleemide funktsiooni sisutagasiside mehhanismina ja asendame selle uue tagasisidesüsteemiga. Lisateabe saamiseks vtEsita ja vaata tagasisidet