Presentation is loading. Please wait.

Presentation is loading. Please wait.

講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所 Visual Basic 程式設計 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所.

Similar presentations


Presentation on theme: "講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所 Visual Basic 程式設計 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所."— Presentation transcript:

1 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所
Visual Basic 程式設計 講師:戴志華 國立台灣大學電機工程研究所

2 第七章 繪圖世界 繪圖函式 繪圖控制項

3 Print函式 Print:畫出文字 CurrentX:x座標值 CurrentY:y座標值 For i=1 to 5
print “CurrentX=”;CurrentX, _ “CurrentY=”;CurrentY Next i Form的屬性 ,不用宣告

4 Print函式(cont’d) 改變CurrentX與CurrentY的值可以改變文字的位置 Randomize Cls
For i=1 to 5 CurrentX=Rnd()*Width CurrentY=Rnd()*Height print “test” Next i

5 座標系統 修改表單(form)的ScaleMode屬性可以改變座標系統 單位大小:表單(Form)的ScaleMode屬性
ScaleWidth, ScaleHeight…… Width, Height…… x軸 可由屬性視 窗修改 (x,y) y軸

6 座標系統(cont’d) vbUser 由程式設計師自訂 vbTwips 1
由程式設計師自訂 vbTwips 1 每吋1440twips,每公分567twips,每點20twips vbPoints 2 每吋72個point vbPixels 3 像素--螢幕上最小的單位 vbCharacter 4 字元 vbInches 5 英吋 vbMillimeters 6 公厘 vbCentimeters 7 公分

7 座標系統(cont’d) 屬性值 說         明 使用者自訂。當改變ScaleTop, ScaleLeft, ScaleHeight, ScaleWidth 值時,系統會自動設ScaleMode = 0 1 以Twip為單位,1 Twip = 1/1440英吋(預設值)。 *2 以點(Point)為單位,1點 = 1/72英吋。 3 以像素(Pixel)為單位,像素為螢幕上的基本單位。 4 以字元(Character)為單位,每個字元高1/6英吋,寬1/12英吋。 5 以英吋(inch)為單位。 6 以公厘(mm)為單位。 7 以公分(cm)為單位。

8 Scale() 語法:[物件.] Scale [(x1 ,y1 )-(x2 ,y2 )] 功能:設定物件內部坐標

9 Scale() Private Sub Form_Load() Me.Scale (-100, 100)-(300,-100)
End Sub (-100,100) (300,-100)

10 利用Scale** 自訂座標系統 也可經由設定ScaleTop, ScaleLeft, ScaleWidth, ScaleHeight四個屬性來自訂座標 Form1.ScaleTop=-100 Form1.ScaleLeft=-100 Form1.ScaleWidth=400 Form1.ScaleHeight=200

11 Line函式:畫線 Line (x1,y1) – (x2,y2)[, 顏色][, B[F]] 顏色: 型式:
vbRed, vbBlue, vbGreen…… RGB(R,G,B)RGB(0,0,255) 型式: 畫線 畫方框:B 畫實心長方形:BF 框線顏色使用ForeColor

12 Line函式:畫線(cont’d) Line (0,0)-(50,50) Line (10,30)-(60,60),vbRed
Line (30,30)-(70,70),vbGreen,B Line (70,70)-(100,100),vbBlue,BF 可試著改變 座標系統

13 顏色 QBColor(i) :利用QBColor函數,以條狀圖來顯示顏色代碼 0-15所對應的顏色。 vbBlack 黑 0,0,0
vbBlue 0,0,255 vbCyan 0,255,255 vbGreen 0,255,0 vbYellow 255,255,0 vbWhite 255,255,255 vbRed 255,0,0 vbMagenta 255,0,255

14 顏色 RGB (Red, Green, Blue) : 使用RGB函數設定顏色 紅(R) 綠(G) 藍(B) 灰藍 範例

15 Point 方法 [object.] point (x, y) 傳回指定位置的色彩值:
PointColor = Point (500, 500)

16 Circle函式:畫圓(橢圓) Circle (x,y) ,r [,color][,起始角度,結束角度][,比率] (x,y):圓心
Private Sub form_click() Circle (50, 50), 30 Circle (80, 80), 30 Circle (100, 100), 20, vbRed, , , 2 End Sub 以後的例子使用vbPixel模式

17 Circle函式:畫弧畫扇(cont’d)
Dim PI As Single PI = Circle (50, 50), 30, , -PI/2, -PI Circle (100, 100), 30, , -PI/2, PI Circle (140, 140), 30, , PI/2, -PI 1/2 π π 0 or 2π 3/2 π

18 PSet:畫點 PSet(x,y),顏色

19 PSet:畫點 (cont’d) 繪製一條拋物線,其方程式:Y= X2 /10 (X為整數且-10≦X≦10)
Private Sub Form_Activate() Scale (-20, 20)-(20, -20) Line (-20, 0)-(20, 0), RGB(0, 0, 255) '畫x軸 Line (0, 20)-(0, -20), RGB(0, 0, 255) '畫y軸 DrawWidth = '設粗細 For x = -10 To 10 PSet (x, x ^ 2 / 10), RGB(255, 0, 0) 'X^2表示X的2次方 Next x End Sub

20 PSet:畫點 (cont’d)

21 DrawStyle 在屬性視窗在修改 DrawStyle=vbSolid vbSolid vbDashDotDot 4 vbDash 1
vbDashDotDot 4 vbDash 1 vbInvisible 5 vbDot 2 vbInsideSolid 6 vbDashDot 3 在屬性視窗在修改 DrawStyle=vbSolid

22 FillStyle vbFSSolid vbUpwardDiagonal 4 vbFSTransparent 1
vbUpwardDiagonal 4 vbFSTransparent 1 vbDownwardDiagonal 5 vbFSHorizontalLine 2 vbCrose 6 vbVerticaLine 3 vbDiagonalCross 7

23 FillStyle值 說 明 實心 1 透明(預設值) 2 水平線 3 垂直線 4 左上到右下的斜線 5 左下到右上的斜線 6 垂直交叉線 7 對角交叉線

24 例子 Private Sub form_click() ForeColor = vbBlack FillColor = vbGreen
Line (10, 10)-(30, 30), , BF Line (40, 40)-(60, 60), , B FillStyle = vbSolid Line (70, 70)-(90, 90), , B FillStyle = vbHorizontalLine Line (100, 100)-(120, 120), , B ForeColor = vbGreen Line (110, 110)-(130, 130), , B End Sub

25 小時鐘II Private Sub Timer1_Timer() Cls Dim hr, min, sec As Integer
Const PI As Single = Dim x, y As Integer hr = Hour(Time) min = Minute(Time) sec = Second(Time) Circle (100, 100), 90 程式還沒完喔

26 小時鐘II(cont’d) x = 100 + 60 * Cos((hr - 3) * (-360 / 12) _
* (PI / 180) + min/60 * (-360 / 12) _ * (PI / 180)) y = * Sin((hr - 3) * (-360 / 12) _ Line (100, 100)-(x, y) x = * Cos((min - 15) * (-360 / 60) _ y = * Sin((min - 15) * (-360 / 60) _ Line (100, 100)-(x, y), vbBlue x = * Cos((sec - 15) * (-360 / 60) _ y = * Sin((sec - 15) * (-360 / 60) _ Line (100, 100)-(x, y), vbRed End Sub

27 小時鐘II(cont’d) 12 2π=360 。 1 。 = π/180 θ=-(hr-3)*(360/12)*(π/180) 3 9
r*sin(θ) θ r*cos(θ) 6

28 Image控制項 Shape 使用控制項的好處: 不會被Cls清除 有分開的訊息 易於管理 etc…… Line Image

29 Image控制項(cont’d) 屬性: Picture:用對話盒選取檔案 Scretch:是否放大、縮小

30 Image控制項(cont’d) 支援的圖形格式 GIF .gif Cursor .cur Bitmap .bmp
Windows meta file .wmf .dib Enhance WMF .emf Icon .ico JPEG .jpg

31 Line控制項 屬性: BorderColor:線條顏色 BorderStyle:線條形式 BorderWidth:線條寬度
X1,Y1:線條起始點 X2,Y2:線條終點

32 BorderStyle vbTransparent vbBSSolid 1 vbBSDash 2 vbBSDot 3 vbBSDashDot
vbBSSolid 1 vbBSDash 2 vbBSDot 3 vbBSDashDot 4 vbBSDashDotDot 5 vbBSInsideSolid 6 注意:與DrawStyle相似,但不同

33 例子 Private Sub form_click() Line1.BorderWidth = 10
Line2.BorderStyle = vbBSDot Line3.Visible = False End Sub

34 Shape控制項 改變Shape屬性值可以轉變成多種形狀 其它屬性 BorderStyle BorderWidth FillStyle ……
vbShapeRectangle vbShapeCircle vbShapeOval vbShapeRoundedRectangle vbShapeSquare vbShapeRoundedSquare

35

36 習題 設計一個可以畫出二元二次方程式的圖形,請自行設定PictureBox的座標系統史琪左上角和右下角座標分別為(-100,500)和(100,-500)

37


Download ppt "講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所 Visual Basic 程式設計 講師:戴志華 hana@arbor.ee.ntu.edu.tw 國立台灣大學電機工程研究所."

Similar presentations


Ads by Google