VB可用object.Line - (x2, y2)寫法實(shí)現(xiàn)在對(duì)象上繪制連續(xù)折線。
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營(yíng)銷、網(wǎng)站重做改版、臨澧網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、購(gòu)物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為臨澧等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
Line?方法,在對(duì)象上畫直線和矩形。
以下是具體實(shí)現(xiàn)繪制曲線的代碼:
Option?Explicit
Const?PI?=?3.14159265432
Private?Sub?Command1_Click()
Picture1.Scale?(-2?*?PI,?1)-(2?*?PI,?-1)?'建立坐標(biāo)系
Dim?I?As?Single
Picture1.CurrentX?=?-2?*?PI?'建立當(dāng)前坐標(biāo)
Picture1.CurrentY?=?0
For?I?=?-2?*?PI?To?2?*?PI?Step?0.01
Picture1.Line?-(I,?Cos(3?*?I)?*?Sin(5?*?I)),?vbRed?'繪制曲線
Next
End?Sub
運(yùn)行效果:
Dim b As New Bitmap(PictureBox1.Width, PictureBox1.Height)
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
直接這樣寫:
line(X1,Y1)-(X2,Y2)
line -(X3,Y3)
這樣第二次畫線就是和第二個(gè)點(diǎn)是連在一起的。
這個(gè)比例的問(wèn)題,你可以先用控件line在窗體上畫出一個(gè)大概的線,經(jīng)調(diào)整之后取line1的
X1,X2,Y1,Y2屬性值就可以了。這樣畫出來(lái)的線就比較協(xié)調(diào)了。
Dim PtStart As Point '記錄繪制直線的起始點(diǎn)
Dim PtEnd As Point '記錄繪制直線的終點(diǎn)
Dim ShouldDrawLine As Boolean '是否繪制直線
'記錄鼠標(biāo)左鍵點(diǎn)擊的位置,第二次點(diǎn)擊后開(kāi)始繪制直線
Private Sub Pic1_MouseDown()Sub Pic1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Pic1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
If Not ShouldDrawLine Then
PtStart = New Point(e.X, e.Y)
ShouldDrawLine = True
Else
PtEnd = New Point(e.X, e.Y)
'下面兩句根據(jù)需要進(jìn)行取舍
'Call DrawLine(PtStart, PtEnd) '繪制一條直線
Call DrawLines(PtStart, PtEnd) '繪制多條直線
ShouldDrawLine = False
End If
End If
End Sub
'繪制鼠標(biāo)兩次點(diǎn)擊位置之間的直線
Private Sub DrawLine()Sub DrawLine(ByVal mPoint1 As Point, ByVal mPoint2 As Point)
Pic1.Refresh() '用于刷新Picturebox表面
Pic1.CreateGraphics.DrawLine(Pens.Blue, mPoint1, mPoint2) '繪制兩點(diǎn)間的直線
End Sub
'繪制多條直線,每?jī)纱问髽?biāo)點(diǎn)擊確定一條線
Private Sub DrawLines()Sub DrawLines(ByVal mPoint1 As Point, ByVal mPoint2 As Point)
'此句不可刪除,用于清除鼠標(biāo)點(diǎn)擊前的軌跡
ControlPaint.DrawReversibleLine(Pic1.PointToScreen(mPoint1), Pic1.PointToScreen(mPoint2), Color.Red)
Pic1.CreateGraphics.DrawLine(Pens.Blue, mPoint1, mPoint2) '繪制兩點(diǎn)間的直線
End Sub