c# draw a line
阿新 • • 發佈:2018-12-19
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Pen pen = new Pen(Color.Red, 5); Point point1 = new Point(10, 50); Point point2 = new Point(100, 50); Graphics g = this.CreateGraphics(); g.DrawLine(pen, point1, point2); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pen = new Pen(Color.Red, 5); Point point1 = new Point(10, 50); Point point2 = new Point(100, 50); g.DrawLine(pen, point1, point2); } private void button1_Click_1(object sender, EventArgs e) { } } }
if you run the program,you will get the following window.