vb.net DrawArc在Picturebox中不会刷新

时间:2015-12-23 18:03:54

标签: vb.net drawing picturebox

我正在尝试显示在图片框中绘制的动画弧。我无法在每个循环(每100度)绘制弧线。油漆仅在子程序结束时触发,最终弧度为300度。如何在每次循环期间强制刷新图片框?这是我的代码和表格。

BitSet

enter image description here

我尝试在循环中使用picturebox1.refresh(),update(),invalidate()但没有成功。

1 个答案:

答案 0 :(得分:2)

如果您改用计时器怎么办?

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