我正在使用vb.net 2008Express进行频谱分析应用程序,该应用程序将频谱图像绘制到picturebox中。我使用缓冲图形的速度和调用一个从画图事件的抽签例程。在大多数情况下,这是很好的工作,但当另一个窗口移动,当我回到我的窗口被覆盖的部分是空白的。我已经确定擦除是在从picturebox.paint事件调用抽签例程之后发生的。如果我再次调用绘图例程(在本例中是由Spectra_MouseUp引起的),则图像将被完全重绘。
回到窗口后,我想不出如何保存(或重绘)整个图像。
我的代码的相关部分如下:
Private currentContext As BufferedGraphicsContext
Private spectraBuffer As BufferedGraphics
Private Sub DrawSpectra()
Dim Gr As Graphics
spectraBuffer = currentContext.Allocate(Spectra.CreateGraphics, Spectra.DisplayRectangle)
Gr = spectraBuffer.Graphics
'.
'.
'. Lots of drawing stuff here such as.... (yes, everything here is declared)
If FillSpectra Then
Gr.DrawPolygon(BasePen, ptsSpec.ToArray)
Gr.FillPolygon(BaseBrush, ptsSpec.ToArray)
Else
Gr.DrawLines(BasePen, ptsSpec.ToArray)
End If
'.
'.
' Render the contents of the buffer to the Spectra window.
spectraBuffer.Render()
End Sub
Private Sub frmMCAWindow_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated
Call DrawSpectra()
' DrawSpectra() works fine from here
End Sub
Private Sub Spectra_MouseUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles Spectra.MouseUp
Call DrawSpectra()
End Sub
Private Sub Spectra_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Spectra.Paint
' When dragging another window over mine, DrawSpectra() works fine here to keep the image in the picturebox
Debug.Print("Begin Spectra_Paint()")
Call DrawSpectra()
' I put a 1 sec. sleep for testing, the image stayed complete while waiting
' The part that was covered was erased once the sleep completed.
Debug.Print("End Spectra_Paint()")
End Sub发布于 2014-05-22 19:25:29
谢谢克里斯。结果是使用Spectra.CreateGraphics而不是PaintEventArgs (对于e.Graphics)才是问题所在。我重新做了下面的工作&它现在工作得很好。
Private currentContext As BufferedGraphicsContext
Private spectraBuffer As BufferedGraphics
Private Sub frmMCAWindow_Activated(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Activated
Spectra.Invalidate()
End Sub
Private Sub Spectra_MouseUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles Spectra.MouseUp
Spectra.Invalidate()
End Sub
Private Sub Spectra_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Spectra.Paint
Dim Gr As Graphics
spectraBuffer = currentContext.Allocate(e.Graphics, Spectra.DisplayRectangle)
Gr = spectraBuffer.Graphics
'.
'.
'. Lots of drawing stuff here such as....
If FillSpectra Then
Gr.DrawPolygon(BasePen, ptsSpec.ToArray)
Gr.FillPolygon(BaseBrush, ptsSpec.ToArray)
Else
Gr.DrawLines(BasePen, ptsSpec.ToArray)
End If
'.
'.
' Render the contents of the buffer to the Spectra window.
spectraBuffer.Render()
End Subhttps://stackoverflow.com/questions/23790689
复制相似问题