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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | namespace _103303058_0601_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { g = this.CreateGraphics(); pen1 = new Pen(Color.GreenYellow, 3); ClickPoint = new Point[99]; PointCounter = 0; fromClick = Color.PowderBlue; } private void Form1_Paint(object sender, PaintEventArgs e) { g.Clear(fromClick); SolidBrush brush = new SolidBrush(Color.Gold); Font font = new Font("標楷體", 17); g.DrawString("繪至黃色文字,字體樣式為標楷體,字型大小17", font, brush, 35,20); //g.DrawLine(pen1, new Point(0, 0), new Point(100, 100)); for (int i = 0; i <= PointCounter; i = i + 2) { g.DrawLine(pen1, ClickPoint[i], ClickPoint[i + 1]); } } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) //將起點存入 { ClickPoint[PointCounter] = new Point(e.X, e.Y); PointCounter += 1; } else if (e.Button == MouseButtons.Right) { g.DrawRectangle(pen1, 0, 0, 300, 300); } } private void Form1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) //將終點存入 { ClickPoint[PointCounter] = new Point(e.X, e.Y); PointCounter += 1; Form1_Paint(sender, null); } } private void Form1_Click(object sender, EventArgs e) { fromClick = Color.SkyBlue; } private void Form1_DoubleClick(object sender, EventArgs e) { fromClick = Color.Silver; } } } 小畫家程式 |
Direct link: https://paste.plurk.com/show/u0mQDpBKSZsrgV2BJlR6