i find it is a good way to learn c sharp,i can save the code on csdn,and it is very easy to browse and consult.
function:click a button to clear the line that drew
add two buttons in the window
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 button1_Click_1(object sender, EventArgs e)
{
// Clear screen with teal background.
using (Graphics g = this.CreateGraphics())
{
g.Clear(this.BackColor);
}
}
}
}
result
if you draw
if you push the clear button,the line will disappear