0
我的代碼圖形在面板上消失滾動
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Using myPen As New Pen(Drawing.Color.BurlyWood, 6)
If upTimer.Enabled = True Then
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)
End If
If leftTimer.Enabled = True Then
e.Graphics.DrawLine(myPen, x1, y1, x2, y1)
End If
If rightTimer.Enabled = True Then
e.Graphics.DrawLine(myPen, x1, y1, x2, y1)
End If
If downTimer.Enabled = True Then
e.Graphics.DrawLine(myPen, x1, y1, x1, y2)
End If
End Using
End Sub
其中x1,y1,x2和y2中的Form_Load被initalized爲零。
定時器代碼是:
Private Sub upTimer_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
y2 = y2 + 5
End Sub
Private Sub leftTimer_Tick(sender As Object, e As EventArgs) Handles leftTimer.Tick
x2 = x2 - 5
End Sub
Private Sub rightTimer_Tick(sender As Object, e As EventArgs) Handles rightTimer.Tick
x2 = x2 + 5
End Sub
Private Sub downTimer_Tick(sender As Object, e As EventArgs) Handles downTimer.Tick
y2 = y2 - 5
End Sub
我已經四個按鈕,以使這四個timers.Now的問題是,當我自動滾動包含在面板中的圖片框或手動附圖得到disappeared.How可以我避免這件事?
我試圖在面板滾動事件PictureBox1.Refresh(),但同樣的事情正在發生。行正在消失。我想補充說,計時器(一次一個是不斷運行)。 –
無論如何,在定時器中添加刷新,但我認爲(恕我直言)你錯了邏輯。嘗試這些更改:在繪畫事件中,只添加一條繪製線,只添加一個定時器,並添加4個布爾全局變量。在你的按鈕上設置布爾變量爲真或假(例如:btn1 set blnDirectionUP = true),在計時器中檢查布爾值並確定x2/y2,最後在計時器滴答和滾動事件結束時添加picturebox的更新。如果我明白你的所作所爲,就是這樣。 :) – Baro