Dim g As Graphics = Me.PictureBox1.CreateGraphics()
Dim p_blue As New Pen(Color.Blue, 1)
Dim p_black As New Pen(Color.Black, 1)
Dim p_red As New Pen(Color.Red, 1)
Dim x_all = PictureBox1.Width
Static xx1 As Integer
Static yy1 As Integer
Static yin As Integer
yin = yin + 1
yy1 = CInt(Math.Sin(yin * 0.01745) * 70) ' Y軸值大小 -70 ~ 70
xx1 = xx1 + 1 'X方向遞增 但是GDI限定只能是整數點 最小間隔 1
Dim scale_x = xx1 + CInt(Me.PictureBox1.Width / 2) '重訂起始中心X座標 >> 正中間
Dim scale_y = -yy1 + CInt(Me.PictureBox1.Height / 2) '重訂起始中心Y座標
Dim scale_x_0 = CInt(Me.PictureBox1.Width / 2)
Dim scale_y_0 = CInt(Me.PictureBox1.Height / 2) '中心
Dim ppp As Pen '定義 ppp 物件是 pen 類別
'yy1 = 100
Static turn As Integer ' 用來調換ppp 繪圖顏色的條件
If xx1 Mod 180 = 0 Then '每180度 清除圖表
PictureBox1.Refresh()
End If
'---------------------------------------------------------------------
If scale_x = Me.PictureBox1.Width Then '當繪圖X方向到底 則跳往左半邊繼續畫
turn = turn + 1 '紀錄第幾次跳換邊界
xx1 = -CInt(Me.PictureBox1.Width / 2)
End If
'------------------------------------------------------------
If turn Mod 2 = 1 Then
ppp = p_blue ' 指定ppp的顏色
Else
ppp = p_black
End If
'--------------------------------------------------------
g.DrawEllipse(ppp, scale_x, scale_y, 2, 2) '以ppp為畫筆 描點
g.DrawLine(ppp, scale_x, CInt(Me.PictureBox1.Height / 2), scale_x, scale_y) '描stem
' me.TextBox1.Text = yy1 & "," & me.TextBox1.Text '測試用
'-------標上刻度----------------------------------------------------
Dim b_red As New SolidBrush(Color.Red) '要先建立b_red 的 SolidBrush類別物件下面要用到Brush
' ps: NET cf 下 沒有 BRUSHES 物件 ,只能自己以 SolidBrush 類別來創brush物件
Dim interval = 30 '刻度範圍大小
Dim interval_N = CInt(x_all / interval) '將 X軸 刻上 N個度
For NN = 1 To interval_N
g.DrawLine(p_red, NN * interval, scale_y_0 + 5, NN * interval, scale_y_0 - 5) '畫刻度
g.DrawString(NN * interval, Me.Font, b_red, NN * interval, scale_y_0 + 5) '標數值
Next
'--------/標上刻度/----------------------------------------------
g.DrawLine(p_black, 0, CInt(Me.PictureBox1.Height / 2), CInt(Me.PictureBox1.Width), CInt(Me.PictureBox1.Height / 2)) 'x軸
g.DrawLine(p_black, CInt(Me.PictureBox1.Width / 2), 0, CInt(Me.PictureBox1.Width / 2), CInt(Me.PictureBox1.Height)) 'y軸
g.DrawLine(p_black, CInt(0), 0, CInt(0), CInt(Me.PictureBox1.Height)) 'y-左邊界
g.DrawLine(p_black, CInt(Me.PictureBox1.Width - 1), 0, CInt(Me.PictureBox1.Width - 1), CInt(Me.PictureBox1.Height)) 'y右邊界
請先 登入 以發表留言。