Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height)
按需網(wǎng)站策劃可以根據(jù)自己的需求進(jìn)行定制,網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作構(gòu)思過(guò)程中功能建設(shè)理應(yīng)排到主要部位公司網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作的運(yùn)用實(shí)際效果公司網(wǎng)站制作網(wǎng)站建立與制做的實(shí)際意義
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(Color.White)
Dim p As New Pen(Color.Black)
p.EndCap = Drawing2D.LineCap.ArrowAnchor
g.DrawLine(p, 30, PictureBox1.Height - 30, 30, 30)
g.DrawLine(p, 30, PictureBox1.Height - 30, PictureBox1.Width - 30, PictureBox1.Height - 30)
Dim i As Integer
Dim bs As New SolidBrush(Color.Green)
Dim po As New Point
po.X = 0
po.Y = PictureBox1.Height - 35
For i = 700 To 1000 Step 50
g.DrawString(i, Me.Font, bs, po.X, po.Y)
g.DrawLine(p, po.X + 28, po.Y + 5, po.X + 30, po.Y + 5)
po.Y -= (PictureBox1.Height - 100) / 6
Next
po.X = 30
po.Y = PictureBox1.Height - 30
For i = 0 To 40 Step 5
g.DrawString(i, Me.Font, bs, po.X, po.Y + 5)
g.DrawLine(p, po.X, po.Y + 2, po.X, po.Y)
po.X += (PictureBox1.Width - 100) / 8
Next
PictureBox1.Image = b
繪圖是系統(tǒng)內(nèi)部操作的,不需要懂原理
方法就在那里,只有會(huì)用和不會(huì)用,你的代碼告訴它繪制,它就會(huì)繪制。它(方法)究竟如何去繪制的并不是重點(diǎn),反正它會(huì)繪制。
drawline(繪線)方法很簡(jiǎn)單,第一個(gè)參數(shù)是pen,它確定線條的顏色、寬度和樣式。第二、第三個(gè)參數(shù)都是point類(lèi)型,確定兩個(gè)點(diǎn)的位置,繪制直線。
不引用的話,VB做不到。這事情要看VB的版本。如果是6.0的話,要去網(wǎng)上下載GDIPLUS的庫(kù)文件或者自己聲明GDI+的API。如果是VB.NET的話,VB自帶GDI+,但是也可以下載GDIPLUS庫(kù)來(lái)用。如果不知道去哪里下載,我下載有,你可以問(wèn)我要。我使用VB6.0。下載gdiplus以后,在VB里面引用這個(gè)庫(kù),注意要選擇“所有文件”才能看到這個(gè)庫(kù)。gdi+里面的path功能可以實(shí)現(xiàn)樣條:Private
TOKEN
As
Long'GDI+對(duì)象
Private
Graphics
As
Long'畫(huà)板
Private
Sub
InitGDIPlus()
'初始化GDI+
Dim
uInput
As
GdiplusStartupInput
uInput.GdiplusVersion
=
1
If
GdiplusStartup(TOKEN,
uInput)
Ok
Then
'初始化錯(cuò)誤
MsgBox
"GDI+
初始化錯(cuò)誤。程序即將關(guān)閉。",
vbCritical,
"InitError"
End
End
If
GdipCreateFromHDC
Me.hDC,
Graphics'創(chuàng)建畫(huà)板
GdipSetSmoothingMode
Graphics,
SmoothingModeAntiAlias'設(shè)置為反鋸齒
End
SubPrivate
Sub
TerminateGDIPlus()
GdipDeleteGraphics
Graphics
'釋放graphics占用的內(nèi)存
GdiplusShutdown
TOKEN
'關(guān)閉GDI+
End
SubPrivate
Sub
Form_Load()
InitGDIPlus
'初始化End
SubPrivate
Sub
Command1_Click()
Dim
path
As
Long
Dim
m(3)
As
POINTF
'以下是坐標(biāo),你可以自由改變
m(0).x
=
m(0).y
=
m(1).x
=
10
m(1).y
=
100
m(2).x
=
20
m(2).y
=
3
m(3).x
=
500
m(3).y
=
100
Dim
pen
As
Long
GdipCreatePen1
HFF000000,
2,
UnitPixel,
pen
'創(chuàng)建畫(huà)筆,用來(lái)畫(huà)出樣條
GdipCreatePath
FillModeAlternate,
path
'創(chuàng)建path
GdipAddPathBeziers
path,
m(0),
4
'創(chuàng)建樣條'Count是說(shuō)坐標(biāo)的個(gè)數(shù),points只能傳遞數(shù)組的第一個(gè)元素,不能傳遞數(shù)組。
GdipDrawPath
Graphics,
pen,
path
'畫(huà)出樣條
GdipDeletePen
pen
'刪除畫(huà)筆
GdipDeletePath
path
'刪除樣條End
SubPrivate
Sub
Form_Unload(Cancel
As
Integer)
TerminateGDIPlus
'刪除GDI+
End
Sub