看板 Visual_Basic 關於我們 聯絡資訊
一時興起寫了以下的code,就算是範例吧 獻醜了 http://dpaste.com/hold/59527/ --- NAME drawpie - 簡易圓餅圖繪製工具 SYNOPSIS drawpie(g, pieLeft, pieTop, pieWidth, pieHeight, colors(), slices()) PARAMETERS g 要畫圖的graphics pieLeft 圓餅圖的左上角X座標(想像一個圓的外接正方形的左上方頂點) pieTop 圓餅圖的左上角Y座標 pieWidth 圓餅圖寬度 pieHeight 圓餅圖高度 colors() brush陣列,畫圓餅圖各塊要用的顏色 slices() integer陣列,圓餅圖各塊的百分比。是百分比喔!不是角度喔! REMARKS * 本sub不檢查slices()中各項總和是否為100,所以使用者要自己注意。 (不過這樣可以玩點花樣,例如畫不從正上方開始的圓餅圖) * colors可以包含任意數量的brush,不會發生錯誤。如果brush比slice多, 多出來的不會用到;如果brush比slice少,那麼各個slice會循環使用顏色。 如果colors中只有一個brush就是指定所有的slice為同一個顏色。 * 本sub會自動給每個slice加白邊,還沒有寫給每個slice畫不同邊的code, 但是很容易改出來。 * 還有以前很多商業圖範例都會做的某一塊pie外推若干pixels,目前也沒 寫,不過自己寫也很容易,用一點cos()和sin()就可以了。   --- Public Class Form1 Private Sub drawpie(ByRef g As Graphics, ByVal pieLeft As Integer, ByVal pieTop As Integer, _ ByVal pieWidth As Integer, ByVal pieHeight As Integer, _ ByRef colors As Brush(), ByRef slices As Integer()) Dim i As Integer, j As Integer, startAngle As Integer = -90 Dim borderPen As Pen = New Pen(Color.AntiqueWhite, 2.5) Dim sliceDeg As Integer Try j = LBound(colors) For i = LBound(slices) To UBound(slices) sliceDeg = slices(i) * 360 / 100 g.FillPie(colors(j), pieLeft, pieTop, pieWidth, pieHeight, startAngle, sliceDeg) g.DrawPie(borderPen, pieLeft, pieTop, pieWidth, pieHeight, startAngle, sliceDeg) startAngle += sliceDeg j += 1 If j > UBound(colors) Then j = LBound(colors) Next i Catch ex As Exception End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim b As Bitmap = New Bitmap(Pic1.Width, Pic1.Height) Dim g As Graphics = Graphics.FromImage(b) g.Clear(Color.Gray) g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias Dim pieleft As Integer = 10, pieTop As Integer = 10 Dim pieWidth As Integer = Pic1.Width - pieleft - 10 Dim pieHeight As Integer = Pic1.Height - pieTop - 10 Dim piecolors As Brush() = {Brushes.RoyalBlue, Brushes.Lime, Brushes.Turquoise, Brushes.SaddleBrown} Dim pieslices As Integer() = {34, 19, 16, 10, 9, 7, 5} drawpie(g, pieleft, pieTop, pieWidth, pieHeight, piecolors, pieslices) Pic1.Image = b End Sub End Class -- BATCH 1 (4/20) - 如何隱身 - SPAM - 英國殺人笑話 - http://tinyurl.com/65vvbx BATCH 2 (5/10) - 當眾脫褲 - 主教 - 傻蛋奧運會 - http://tinyurl.com/68grk7 BATCH 3 (6/14) - 買張床 - 切達大俠 - 伐木人之歌 - http://tinyurl.com/3zpyx5 ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ 蒙帝派松正體中文計畫 Spam-a-lot and enjoy the pythonesque delight! ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.199.251 ※ 編輯: MOONRAKER 來自: 59.115.213.174 (06/28 11:16)