简体   繁体   中英

In Visual Basic 2022, can I interrupt a panel.Refresh() in the middle of plotting on the panel?

I am plotting a Julia Set in a panel named pnlGraph that is 601 x 601 pixels. I determine the color of each pixel in a Paint event, and plot the entire Set using the command pnlGraph.Refresh(). It takes the PC about a minute to plot all 361,201 pixels. If I see an error early in the process of the panel refreshing, I would like to be able to interrupt the refresh and do something else.

I have searched the internet and found something called DoEvents() that I am unable to use properly. Can anyone help me use DoEvents() or some other method to interrupt a panel in mid-refresh in order to save time? Thank you.

@Jimi's suggestion to use a bitmap instead of the paint event worked wonders, cutting down the time to display the image by over 80%. If I use fewer iterations, the bitmap appears almost instantaneously. That means I don't have to wait over a minute to display each image, which solves my problem.

Here's the code I developed in a separate project to create the bitmap. It's more complicated in the program I wanted it for, but this cuts out all the code that is not needed to solve my problem. I deleted the Panel and replaced it with a PictureBox called pbxFractal. That's where I placed the bitmap image. Very cool stuff.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim i, j, i1, j1 As Int16

    Dim fractalBitmap As Bitmap = New Bitmap(601, 601)

    Dim pixColor As Color

    For i = 0 To 600
        For j = 0 To 600

            i1 = i Mod 256
            j1 = j Mod 256
            pixColor = Color.FromArgb(255, i1, j1, Math.Abs(i1 - j1))
            fractalBitmap.SetPixel(i, j, pixColor)

        Next j
    Next i

    pbxFractal.Image = fractalBitmap

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM