在点P1(10,10)和P2(100,50)之间画一条红色的线段
private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen p1 = new Pen(Color.Red, 2); g.DrawLine(p1, 10, 10, 100, 50); }
使用BackwardDiagonal、Vertical,Cross等图案填充饼图。
private void button1_Click(object sender, EventArgs e) { HatchBrush h1 = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Gold), h2 = new HatchBrush(HatchStyle.Cross, Color.Yellow), h3 = new HatchBrush(HatchStyle.Vertical, Color.Snow); Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); g.FillPie(h1, 10, 10, 200, 200, 0, 60); g.FillPie(h2, 210, 210, 200, 200, 0, 120); g.FillPie(h3, 410, 410, 200, 200, 0, 180); }
在PictureBox1内部画一个绿色的椭圆边框。
private void button1_Click(object sender, EventArgs e) { Graphics g = pictureBox1.CreateGraphics(); Pen p = new Pen(Color.Green, 1); g.DrawEllipse(p, 10, 10, 200, 100); }用黄色填充一个绿色椭圆。
private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); Brush b = new SolidBrush(Color.Yellow); Pen p = new Pen(Color.Green, 2); g.DrawEllipse(p, 10, 20, 100, 200); g.FillEllipse(b, 10, 20, 100, 200); }
private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); float a = this.Width / 2, b = this.Height / 2; g.TranslateTransform(a,b); Pen p = new Pen(Color.Green , 4); float x1, y1, x2, y2, t, t1,e1; for (t = 0; t < 50 * 3.1415926; t += 0.0001f) { t1 = t + 3.1415926f / 2; e1 = Convert.ToSingle(Math.Pow(2.718281f, Math.Cos(t1)) - 2 * Math.Cos(4 * t1) + Math.Pow(Math.Sin(t1 / 12), 5)); x1 = Convert.ToSingle(e1 * Math.Cos(t) * 30); y1 = Convert.ToSingle(e1 * Math.Sin(t) * 30); x2 = Convert.ToSingle(e1 * Math.Cos(t + 0.0001f) * 30); y2 = Convert.ToSingle(e1 * Math.Sin(t + 0.0001f) * 30); g.DrawLine(p, x1, y1, x2, y2); } }