編譯器:VS2013
.Net版本:4.5
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); }
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); }
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); }
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); }