一、開發環境 編譯器:VS2013 .Net版本:4.5 二、開發過程 1.畫一條直線 private void btnDrawLine_Click(object sender, EventArgs e) { //創建一個畫圖圖面 Graphics g = this.CreateGraphics()... ...
一、開發環境
編譯器:VS2013
.Net版本:4.5
二、開發過程
1.畫一條直線
private void btnDrawLine_Click(object sender, EventArgs e) { //創建一個畫圖圖面 Graphics g = this.CreateGraphics(); //創建一隻筆 Pen pen = new Pen(Brushes.Red); //直線的兩個坐標 Point pointStart = new Point(10, 10); Point pointEnd = new Point(50, 50); //開始畫 g.DrawLine(pen, pointStart, pointEnd); }
2.畫一個矩形
private void btnDrawRectangle_Click(object sender, EventArgs e) { //創建一個畫圖圖面 Graphics g = this.CreateGraphics(); //創建一隻筆 Pen pen = new Pen(Brushes.DeepSkyBlue); //確定矩形的起點、長和高 g.DrawRectangle(pen, 50, 50, 60, 30); }
3.畫一個字元串
private void btnDrawString_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Font font = new Font("華為宋體", 12); //Point一樣,只是值是浮點類型 PointF point = new PointF(50, 50); g.DrawString("我是Kimisme", font, Brushes.Coral, point); }
4.畫一個扇形
private void btnDrawSector_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.DrawPie(new Pen(Brushes.Green), new Rectangle(new Point(100, 70), new Size(50, 50)), 60, 90); }