vb.net DrawArc 不会在 Picturebox 中刷新
vb.net DrawArc won't refresh in Picturebox
我正在尝试显示在图片框中绘制的动画弧线。我无法在每个循环(每 100 度)处绘制弧线。油漆仅在子例程结束时触发,最终弧度为 300 度。如何在每个循环中强制刷新图片框?这是我的代码和表格。
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim pen As New Pen(Color.Red, 1)
Dim r As Integer = 100
'Delay(2)
Do Until r > 300
e.Graphics.DrawArc(pen, 50, 50, 50, 50, 270, r) ' pen style, x position, y postion, width, height, start point degrees, arc degrees
ListBox1.Items.Add(r)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
r = r + 100
Delay(1)
Loop
e.Dispose()
pen.Dispose()
ListBox1.Items.Add("Done")
End Sub
我试过在循环中使用 picturebox1.refresh()、update()、invalidate() 但没有成功。
如果改用计时器会怎样?
Imports System.Timers.Timer
Public Class Form1
Dim tmr1 As New Timer
Dim r As Int32 = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.DoubleBuffered = True
AddHandler tmr1.Tick, AddressOf tmr1_Tick
With tmr1
.Interval = 1000
.Start()
End With
End Sub
Private Sub tmr1_Tick(ByVal sender As Object, ByVal e As EventArgs)
If r < 300 Then
r += 100
ListBox1.Items.Add(r)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Me.PictureBox1.Invalidate()
Else
ListBox1.Items.Add("Done")
tmr1.Stop()
End If
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim pen As New Pen(Color.Red, 1)
Dim g As Graphics = e.Graphics
Debug.WriteLine("PictureBox1: " & r)
g.DrawArc(pen, 50, 50, 50, 50, 270, r) ' pen style, x position, y postion, width, height, start point degrees, arc degrees
pen.Dispose()
End Sub
End Class
我正在尝试显示在图片框中绘制的动画弧线。我无法在每个循环(每 100 度)处绘制弧线。油漆仅在子例程结束时触发,最终弧度为 300 度。如何在每个循环中强制刷新图片框?这是我的代码和表格。
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim pen As New Pen(Color.Red, 1)
Dim r As Integer = 100
'Delay(2)
Do Until r > 300
e.Graphics.DrawArc(pen, 50, 50, 50, 50, 270, r) ' pen style, x position, y postion, width, height, start point degrees, arc degrees
ListBox1.Items.Add(r)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
r = r + 100
Delay(1)
Loop
e.Dispose()
pen.Dispose()
ListBox1.Items.Add("Done")
End Sub
我试过在循环中使用 picturebox1.refresh()、update()、invalidate() 但没有成功。
如果改用计时器会怎样?
Imports System.Timers.Timer
Public Class Form1
Dim tmr1 As New Timer
Dim r As Int32 = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.DoubleBuffered = True
AddHandler tmr1.Tick, AddressOf tmr1_Tick
With tmr1
.Interval = 1000
.Start()
End With
End Sub
Private Sub tmr1_Tick(ByVal sender As Object, ByVal e As EventArgs)
If r < 300 Then
r += 100
ListBox1.Items.Add(r)
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
Me.PictureBox1.Invalidate()
Else
ListBox1.Items.Add("Done")
tmr1.Stop()
End If
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim pen As New Pen(Color.Red, 1)
Dim g As Graphics = e.Graphics
Debug.WriteLine("PictureBox1: " & r)
g.DrawArc(pen, 50, 50, 50, 50, 270, r) ' pen style, x position, y postion, width, height, start point degrees, arc degrees
pen.Dispose()
End Sub
End Class