创建画布的3种方法:
1.最常用的就是Button按钮,方便刷新时间
Private void button1_Click (object Sender, EventArgs e)
{
Graphics g=this.CreateGraphics();
}
2.Paint控件的应用:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
g = e.Graphics;
}
3. Panel 控件用于为其他控件提供可识别的分组,可以用作画布
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
}
画圆的几种画法:
private void button1_Click_1(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TranslateTransform((float)(40), (float)(40));
g.FillEllipse(new SolidBrush(Color.Green), 120, 120, 200, 200);
Pen pen = new Pen(Color.Gold, 2);
g.DrawEllipse(pen, 120, 120, 200, 200);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.TranslateTransform((float)(100), (float)(100));
Pen pen = new Pen(Color.Gold, 2);
g.DrawEllipse(pen, 10, 10, 200, 200);
}