Pen 是一個用來在 Graphics 畫布上繪製時,所使用的畫筆工具。
● 建立 Pen 物件的語法
' 建立一個名為 p 畫筆物件 Dim p As New Pen (Color.Blue, 4) |
' 建立一個名為 p 畫筆物件 Dim p As Pen p = New Pen (Color.Blue, 4) |
' 將 p 畫筆顏色更改為黃色 p.Color = Color.Yellow ' 將 p 畫筆粗細更為 10 p.Width = 10 |
◎ DrawLine 方法 -- 劃一條直線
myGraphics.DrawLine ( myPen, x1 , y1 , x2 , y2 ) -- x1 , y1 (起點位置) , x2 , y2 (終點位置)
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawLine ( p , 100 , 200 , 50 , 70 ) |
Dim g As Graphics g.DrawLine ( New Pen (Color.Blue, 4) , 100 , 200 , 50 , 70 ) |
◎ DrawRectangle 方法 -- 劃一個矩形
myGraphics.DrawRectangle ( myPen, x , y , width , height ) -- x , y (左上角座標位置) , width (矩形寬度) , height (矩形高度)
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawRectangle ( p , 100 , 200 , 50 , 70 ) |
◎ DrawEllips 方法 -- 劃一個橢圓
myGraphics.DrawEllips ( myPen, x , y , width , height )
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawEllips ( p , 10 , 50 , 60 , 40 ) |
◎ DrawPolygon 方法 -- 劃一個多邊形
myGraphics.DrawPolygon ( myPen, myPts )
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) ' 必須先宣告 Point() 陣列變數,在陣列內設定點的位置 Dim pts As Point() = {New Point(275,50),New Point(300,100),New Point(250,100)} ' 畫三角形 g.DrawPolygon ( p , pts ) |
◎ DrawCurve 方法 -- 劃一條基本曲線
myGraphics.DrawCurve ( myPen, myPts)
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) ' 曲線各點先以 Point() 陣列變數宣告,不限定點數 Dim pts As Point = {New Point(275,50),New Point(300,100),New Point(350,50),New Point(400,75)} g.DrawDrawCurve ( p , pts ) |
◎ DrawBezier 方法 -- 劃一條貝茲曲線 (必須設定四個座標以決定曲線)
myGraphics.DrawBezier ( myPen, p1 , p2 , p3 , p4 )
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) Dim pts1 As Point = New Point (220 , 40) Dim pts2 As Point = New Point (230 , 120) Dim pts3 As Point = New Point (260 , 40) Dim pts4 As Point = New Point (270 , 120) g.DrawBezier ( p , pts1, pts2 , pts3 , pts4 ) |
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawBezier ( p , New Point (220 , 40), New Point (230 , 120), New Point (260 , 40) , New Point (270 , 120) ) |
◎ DrawPie 方法 -- 劃一個扇形
myGraphics.DrawPie ( myPen, x , y , width , height , startAngle , sweepAngle ) -- startAngle(起始角度) , sweepAngle(扇形角度大小,負值表示逆時針) ※
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawPie ( p , 0 , 0 , 50 , 30 , 45 , 270) |
◎ DrawArc 方法 -- 劃一條圓弧
myGraphics.DrawArc ( myPen, x , y , width , height , startAngle , sweepAngle ) -- startAngle(起始角度) , sweepAngle(圓弧角度大小,負值表示逆時針) ※
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawArc ( p , 0 , 0 , 50 , 30 , 45 , 135 ) |
◎ DrawPie 方法 -- 劃一個扇形
myGraphics.DrawPie ( myPen, x , y , width , height , startAngle , sweepAngle ) -- startAngle(起始角度) , sweepAngle(扇形角度大小)
Dim g As Graphics Dim p As New Pen (Color.Blue, 4) g.DrawPie ( p , 0 , 0 , 50 , 30 , 45 , -90 ) |
※ 有關 startAngle 與 sweepAngle 是圓弧的起點與終點,若是負值則為逆時針。其角度說明如下:
留言列表