简单的画线,郁闷了我好几天
在panel和pictureBox中的画法都是一样的
public void pictureBox1_ht()//画图的简单方法
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Color.Red, 2), x, 20, x, 40);
}
private void button2_Click(object sender, EventArgs e)
{
x = Convert.ToInt32(textBox1.Text);
y = Convert.ToInt32(textBox1.Text);
pictureBox1.Invalidate();//刷新 pictureBox图 要是只有这句话 还要重写OnPaint方法
//pictureBox1.Load("tt.bmp");//重新加载图片 图片位置在bin中
pictureBox1.Update();//这句话相当关键 会是消除之前画的图 速度加快
pictureBox1_ht();
}
//--------------------------------------------------
protected override void OnPaint(PaintEventArgs e)//重写
{
panel1_ht();
}
public void panel1_ht()
{
Graphics g = pictureBox1.CreateGraphics();
g.DrawLine(new Pen(Color.Red, 2), x, 20, x, 40);
}
private void button2_Click(object sender, EventArgs e)
{
x = Convert.ToInt32(textBox1.Text);
y = Convert.ToInt32(textBox1.Text);
pictureBox1.Invalidate();
//pictureBox1.Load("tt.bmp");
//ctureBox1.Update();
panel1_ht();
}