Beginning VB 2008 從入門到精通 ;ID=181830 Pro VB 2008 and the .NET 3.5 Platform ;ID=184746 Visual Basic 2008 Programmerss Reference ;ID=181605 Apress Accelerated VB 2008 ;ID=181504 Visual Basic 2008 Step by Step Wrox Professional VB 2005 with .NET 3.0 ;ID=158893 Build A Program Now Visual Basic 2005 ;ID=146029 .NET游戲編程入門經(jīng)典—VB.NET篇 ;ID=158821 O'Reilly Visual Basic 2005 Cookbook ;ID=160654 .NET Insight for Classic VB Developers ;ID=162041 Fast Track Visual Basic.NET ;ID=161990 Security for Microsoft Visual Basic.NET ;ID=175012 Visual Basic.NET How to Program 第二版 ;ID=173182 Visual Basic 2005 簡明教程 ;ID=173180 Visual Basic 2005傻瓜書 ;ID=173178 Programming Visual Basic.NET ;ID=173164 Visual Basic .NET Tips and Techniques ;ID=176561 VB開發(fā)人員SQL Sever指南 ;ID=173176 How to Code .NET ;ID=145559 Essential .NET, Volume I ;ID=176152 ADO.NET全攻略 . 查看原帖
創(chuàng)新互聯(lián)建站是少有的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、營銷型企業(yè)網(wǎng)站、小程序開發(fā)、手機(jī)APP,開發(fā)、制作、設(shè)計(jì)、友情鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,自2013年起,堅(jiān)持透明化,價(jià)格低,無套路經(jīng)營理念。讓網(wǎng)頁驚喜每一位訪客多年來深受用戶好評
VB系統(tǒng)的坐標(biāo)原點(diǎn)在左上角,X軸的正方向是水平向右,而Y軸的正方向是垂直向下。所以,要繪制三角函數(shù)的曲線,自己可以通過改變點(diǎn)坐標(biāo)的方法來實(shí)現(xiàn),當(dāng)然,VB.NET提供了相應(yīng)的方法可以來實(shí)現(xiàn)坐標(biāo)變換,也可以通過VB.Net的Graphics類提供的平移、旋轉(zhuǎn)等轉(zhuǎn)換來實(shí)現(xiàn)。
下面是我通過自己變換實(shí)現(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,獲得一個(gè)Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個(gè)Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個(gè)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,獲得一個(gè)Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個(gè)Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個(gè)Brush對象,用于填充圖形(如果需要填充的話)
? Dim MyBrush As New SolidBrush(Color.Orange)
? '聲明橫向和縱向比例變量
? Dim Heng As Integer = 20
? Dim Zong As Integer = 50
? '先獲得正弦值,保存到點(diǎn)坐標(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
? '采用繪制光滑線連接點(diǎn)的方式繪制曲線
? MyGraphics.DrawCurve(MyPen, MyPoints)
End Sub
End Class
顯示的效果圖:
Dim Points1(30) As Point
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer1.Interval = 200
For i = 0 To 30
Points1(i) = New Point(i * 45, Math.Sin(i) * (PictureBox1.Height - 50) / 9)
Points1(i).Offset(-450, Math.Abs(Points1(i).Y - (PictureBox1.Height - 50) / 9) * 3.55 + 43)
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static j As Long
j = j + 1
PictureBox1.Image = x_y(PictureBox1, j)
End Sub
Private Function x_y(ByVal pic As PictureBox, ByVal x As Long) As Bitmap
Dim b As New Bitmap(pic.Width, pic.Height)
Dim g As Graphics = Graphics.FromImage(b)
Dim c
Dim j
g.Clear(Color.YellowGreen)
Dim p As New Pen(Color.WhiteSmoke)
p.EndCap = Drawing2D.LineCap.ArrowAnchor
g.DrawLine(p, 20, pic.Height - 20, 20, 10)
g.DrawLine(p, 20, pic.Height - 20, pic.Width - 20, pic.Height - 20)
Dim i As Double
Dim bs As New SolidBrush(Color.Red)
Dim po As New Point
g.DrawString(-2, Me.Font, bs, 12, pic.Height - 18)
po.X = 0
po.Y = pic.Height - 45
For i = -1.6 To 4 Step 0.4
g.DrawString(Math.Round(i, 1), Me.Font, bs, po.X, po.Y)
g.DrawLine(p, po.X + 18, po.Y + 5, po.X + 20, po.Y + 5)
Dim p1 As New Pen(Color.Blue)
p1.DashStyle = Drawing2D.DashStyle.Dash
g.DrawLine(p1, po.X + 28, po.Y + 5, pic.Width - 20, po.Y + 5)
po.Y -= (pic.Height - 50) / 9
Next
po.X = 20
po.Y = pic.Height - 20
For c = 0 To 14400 Step 1200
If (c / 1200) 0 Then
g.DrawString((c / 1200) + x, Me.Font, bs, po.X - j, po.Y + 5)
End If
g.DrawLine(p, po.X, po.Y + 2, po.X, po.Y)
po.X += (pic.Width - 50) / 12
Next
For i = 0 To Points1.Count - 1
Points1(i).Offset(45, 0)
Next
If x Mod 6 = 0 Then
For i = 0 To Points1.Count - 1
Points1(i).Offset(-270, 0)
Next
End If
g.DrawCurve(Pens.Red, Points1)
'For i = 0 To Points1.Count - 1
'g.DrawString(Math.Sin(i), Me.Font, Brushes.Red, Points1(i))
'Next
Return b
End Function
具體操作步驟如下:
1、首先,單擊左側(cè)工具框中的命令按鈕,如下圖所示,然后進(jìn)入下一步。
? ?
2、其次,雙擊以直接在表單上繪制,如下圖所示,然后進(jìn)入下一步。
?
3、接著,或者可以單擊命令按鈕控件,再在頁面上拖動(dòng)繪制,如下圖所示,然后進(jìn)入下一步。
? ?
4、然后,如果對外觀不滿意,可以在屬性窗口中對其進(jìn)行更改,如下圖所示,然后進(jìn)入下一步。
? ?
5、隨后,可以直接進(jìn)入代碼窗口,如下圖所示,然后進(jìn)入下一步。
? ?
6、最后,編寫號(hào)后,單擊運(yùn)行即可,如下圖所示。這樣,問題就解決了。
? ?