Private mBmpBuffer As Bitmap
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mBmpBuffer = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height, Me.PictureBox1.CreateGraphics)
Dim g As Graphics = Graphics.FromImage(mBmpBuffer)
Dim i As Integer
Dim aa(3, 1) As Single
Dim stra() As String
Try
Dim sr As StreamReader = New StreamReader("D:/模型相关/modeldesign/modelpaint/data.csv")
Dim line As String
Do
line = sr.ReadLine()
i = i + 1
If i > 1 Then
stra = Split(line, ";")
aa(i - 2, 0) = Val(stra(0))
aa(i - 2, 1) = Val(stra(1))
End If
Loop Until line Is Nothing
sr.Close()
Catch ex As Exception
End Try
Dim ix As Single
Dim iy As Single
Dim temp As Single
temp = aa(0, 0)
For i = 0 To 3
If aa(i, 0) > temp Then
temp = aa(i, 0)
End If
Next
ix = temp
temp = aa(0, 1)
For i = 0 To 3
If aa(i, 1) > temp Then
temp = aa(i, 1)
End If
Next
iy = temp
'变换坐标
Dim bx As Single
Dim by As Single
bx = PictureBox1.Width / ix
by = PictureBox1.Height / iy
'Dim g As Graphics = Me.PictureBox1.CreateGraphics
g.Clear(Color.White)
Dim mypoint(3) As Point
Dim n As Integer = 3
'变换坐标原点
g.TranslateTransform(PictureBox1.Width / 15, PictureBox1.Height * 14 / 15)
'g.ScaleTransform(PictureBox1.Width / ix, PictureBox1.Height / iy)
'绘制坐标轴
Dim mypen As New Pen(Color.Black)
Dim sb As New SolidBrush(Color.Black)
'Dim sb1 As Brush = Brushes.Red
Dim mypen1 As New Pen(Color.Blue, 6)
g.DrawLine(mypen, 0, 0, PictureBox1.Width - 40, 0)
g.DrawLine(mypen, 0, 0, 0, 20 - PictureBox1.Height)
For i = 0 To PictureBox1.Width - 40 Step 40
g.DrawLine(mypen, i, 0, i, -10)
g.DrawString(Int(i / 0.9 / bx), New Font("宋体", 8), sb, i - 10, 0)
Next
g.DrawString("C", New Font("宋体", 8), sb, PictureBox1.Width - 50, 0)
For i = 40 To PictureBox1.Height - 40 Step 40
g.DrawLine(mypen, 0, -i, 10, -i)
g.DrawString(Int(i / 0.9 / by), New Font("宋体", 8), sb, -20, -i - 10)
Next
g.DrawString("x", New Font("宋体", 8), sb, -10, 20 - PictureBox1.Height)
'mypen.Width = 1
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
For i = 0 To n
mypoint(i).X = aa(i, 0) * bx * 0.9
mypoint(i).Y = -aa(i, 1) * by * 0.9
'g.FillRectangle(sb1, mypoint(i).X, mypoint(i).Y, 3, mypoint(i).Y)
g.DrawLine(mypen1, mypoint(i).X, 0, mypoint(i).X, mypoint(i).Y)
Next
'开始画线
'g.DrawCurve(mypen, mypoint)
Me.PictureBox1.Refresh()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFilter As String = "BMP文件(*.bmp)|*.bmp"
Dim pdlg As SaveFileDialog = New SaveFileDialog
pdlg.Title = "地图另存为"
pdlg.Filter = strFilter
pdlg.OverwritePrompt = True
pdlg.ShowDialog()
If Not pdlg.FileName.Equals("") Then
If Not (mBmpBuffer Is Nothing) Then
'mBmpBuffer.Save("c:/a.bmp")
mBmpBuffer.Save(pdlg.FileName)
End If
End If
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If Not (mBmpBuffer Is Nothing) Then
e.Graphics.DrawImage(mBmpBuffer, 0, 0)
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Clear()
ComboBox1.Items.Add("模型一")
ComboBox1.Items.Add("模型二")
ComboBox1.Items.Add("模型三")
ComboBox1.Text = "模型一"
End Sub
End Class