定義好三角形的三個點,用line畫線連接即可。
成都網(wǎng)站建設(shè)公司更懂你!創(chuàng)新互聯(lián)只做搜索引擎喜歡的網(wǎng)站!成都網(wǎng)站制作前臺采用搜索引擎認可的DIV+CSS架構(gòu),全站HTML靜態(tài),html5+CSS3網(wǎng)站,提供:網(wǎng)站建設(shè),微信開發(fā),微信小程序定制開發(fā),商城網(wǎng)站開發(fā),成都app軟件開發(fā),域名注冊,服務(wù)器租售,網(wǎng)站代托管運營,微信公眾號代托管運營。
示例如下:
Private?Sub?Form_Load()
Me.AutoRedraw?=?True
Dim?x?As?Integer
Dim?y?As?Integer
CurrentX?=?1500
CurrentY?=?500
Line?-(3000,?2000),?RGB(0,?0,?255)
Line?-(1500,?2000),?RGB(0,?0,?255)
Line?-(1500,?500),?RGB(0,?0,?255)
End?Sub
運行效果:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim g As Graphics = PictureBox1.CreateGraphics
Dim hs As HatchStyle = HatchStyle.Cross
Dim sb As HatchBrush = New HatchBrush(hs, Color.Black, Color.White)
Dim p(3) As Point
p(0).X = 100
p(0).Y = 50
p(1).X = 0
p(1).Y = 100
p(2).X = 200
p(2).Y = 100
p(3).X = 100
p(3).Y = 50
g.FillPolygon(sb, p)
g.DrawPolygon(Pens.Black, p)
End Sub
End Class
VB系統(tǒng)的坐標(biāo)原點在左上角,X軸的正方向是水平向右,而Y軸的正方向是垂直向下。所以,要繪制三角函數(shù)的曲線,自己可以通過改變點坐標(biāo)的方法來實現(xiàn),當(dāng)然,VB.NET提供了相應(yīng)的方法可以來實現(xiàn)坐標(biāo)變換,也可以通過VB.Net的Graphics類提供的平移、旋轉(zhuǎn)等轉(zhuǎn)換來實現(xiàn)。
下面是我通過自己變換實現(xiàn)的示例,提供參考;我的環(huán)境是VB.NET 2010
Imports System.Math
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
? '1,獲得一個Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個Brush對象,用于填充圖形(如果需要填充的話)
? Dim MyBrush As New SolidBrush(Color.Orange)
? MyGraphics.DrawLine(MyPen, 0, 200, 700, 200)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
? '1,獲得一個Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個Brush對象,用于填充圖形(如果需要填充的話)
? Dim MyBrush As New SolidBrush(Color.Orange)
? '聲明橫向和縱向比例變量
? Dim Heng As Integer = 20
? Dim Zong As Integer = 50
? '先獲得正弦值,保存到點坐標(biāo)數(shù)組
? Dim MyPoints(700) As Point
? Dim i As Integer
? For i = 0 To 700
? ? ? MyPoints(i) = New Point(i * Heng, 200 + Sin(i) * Zong)
? Next
? '采用繪制光滑線連接點的方式繪制曲線
? MyGraphics.DrawCurve(MyPen, MyPoints)
End Sub
End Class
顯示的效果圖: