none
VB2008 如何重新呼叫Paint ?? RRS feed

  • 問題

  • 各位先進前輩, 我最近想寫一個畫波型圖的程式!

    我想要的功能是按開始鈕即可以開始畫波形圖, 按下停止鈕, 立即停止繪圖, 並保留當下的圖!!

    我寫了以下程式, 可是不知道該如何重新呼叫Paint來繪圖 :

     Public Class Form_Movement
    Dim Graphicstate As Boolean
    Public X, y1, y2, y3 As Integer
    Public lx, ly1, ly2, ly3 As Integer

    Private Sub Form_Movement_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Form_Main.Visible = False
    Me.btnStart.Visible = True
    Me.btnStop.Visible = False
    Graphicstate = True
    X = 0
    lx = 0
    y1 = 0
    y2 = 0
    y3 = 0
    ly1 = 0
    ly2 = 0
    ly3 = 0
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       basedataProcess()
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    Graphicstate = True
    Timer1.Enabled = True
    Me.btnStart.Visible = False
    Me.btnStop.Visible = True
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    Dim j As Integer
    Dim Waveform = e.Graphics
    Dim XAxis_Color As New Pen(Color.Aquamarine, 1)
    Dim YAxis_Color As New Pen(Color.Yellow, 1)
    Dim ZAxis_Color As New Pen(Color.Lime, 1)
    Dim DashColor As New Pen(Color.LightGray, 1)
    Dim ReColor As New SolidBrush(Color.Black)
    DashColor.DashStyle = Drawing2D.DashStyle.Dash '定義虛線畫筆

    X = 665
    Do Until Graphicstate = False
    lx = X
    X = X + 1 ' 若需要畫斜線再解開此功能
    If X > 664 Then
    X = 0
    Waveform.FillRectangle(ReColor, 0, 0, 665, 480) '畫滿波形後, reset用!
    For j = 1 To 3
    Waveform.DrawLine(DashColor, 0, 120 * j, 664, 120 * j) '畫虛線
    Next j
    Else
    ly1 = y1
    y1 = Int(Axis_X / 4)
    Waveform.DrawLine(XAxis_Color, lx, 120 - ly1, X, 120 - y1) '畫斜線時使用 Waveform.DrawLine(E1Color, lx, 125 - ly1, X, 125 - y1)

    ly2 = y2
    y2 = Int(Axis_Y / 4)
    Waveform.DrawLine(YAxis_Color, lx, 240 - ly2, X, 240 - y2)

    ly3 = y3
    y3 = Int(Axis_Z / 4)
    Waveform.DrawLine(ZAxis_Color, lx, 360 - ly3, X, 360 - y3)

    End If
    'X = X + 1 '畫直線用
    System.Windows.Forms.Application.DoEvents()
    Threading.Thread.Sleep(25)
    Loop
    End Sub
    Private Sub Form_ScreenRotate_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    Me.Invalidate() '螢幕尺寸變更, 重劃圖形!!
    End Sub
    Private Sub Form_Movement_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
    Timer1.Enabled = False
    Graphicstate = False
    Form_Main.SerialPort1.Write("!")
    Me.Dispose()
    Form_Main.Show()
    Me.Close()
    End Sub

    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStop.Click
    System.Windows.Forms.Application.DoEvents()
    Form_Main.SerialPort1.Write("!")
    Timer1.Enabled = False
    Graphicstate = False
    Me.btnStart.Visible = True
      Me.btnStop.Visible = False 
    End Sub
    End Class

    希望各位先進前輩可以幫忙指點迷津, 在此先感謝各位的協助, 謝謝!!

    2010年6月2日 上午 07:44

解答

所有回覆