using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace picturebox
{
public partial class Form1 : Form
{
//设置一个标志
bool flag = false;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
//标志为flase时,不画线
if (flag == false) return;
Graphics g = e.Graphics;
g.DrawLine(Pens.Black, 10, 10, 100, 1000);
}
private void button1_Click(object sender, EventArgs e)
{
//设置标志为true,画线
flag = true;
this.Refresh();
}
private void button2_Click(object sender, EventArgs e)
{
//设置标志为false,将已经画的线删除
flag = false;
this.Refresh();
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace picturebox
{
public partial class Form1 : Form
{
//设置一个标志
bool flag = false;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
//标志为flase时,不画线
if (flag == false) return;
Graphics g = e.Graphics;
g.DrawLine(Pens.Black, 10, 10, 100, 1000);
}
private void button1_Click(object sender, EventArgs e)
{
//设置标志为true,画线
flag = true;
this.Refresh();
}
private void button2_Click(object sender, EventArgs e)
{
//设置标志为false,将已经画的线删除
flag = false;
this.Refresh();
}
}
}