使用图形方法,在Form上画出:
1.? 画出5不同颜色直线并形成一个多边形;
2. 用红色画笔画一个圆形;
3.用图片填充一个矩形。
C#代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Random rand = new Random(); Point[] p = new Point[5]; private void Form1_Paint(object sender, PaintEventArgs e) { Graphics grap = e.Graphics; p[0] = new Point(100, 100); p[1] = new Point(200, 200); p[2] = new Point(100, 300); p[3] = new Point(000, 200); p[4] = new Point(100, 100); Pen pen = new Pen(Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)),2); grap.DrawLines(pen, p); Pen redpen = new Pen(Color.Red, 2); grap.DrawArc(redpen, new Rectangle(new Point(300, 50), new Size(80, 80)), 0, 360); grap.FillRectangle(new TextureBrush(new Bitmap("1.bmp")), new Rectangle(new Point(300, 200), new Size(80, 80))); } } } |
测试结果: