首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除另一个窗口下的部分PictureBox

删除另一个窗口下的部分PictureBox
EN

Stack Overflow用户
提问于 2014-05-21 18:05:41
回答 1查看 155关注 0票数 0

我正在使用vb.net 2008Express进行频谱分析应用程序,该应用程序将频谱图像绘制到picturebox中。我使用缓冲图形的速度和调用一个从画图事件的抽签例程。在大多数情况下,这是很好的工作,但当另一个窗口移动,当我回到我的窗口被覆盖的部分是空白的。我已经确定擦除是在从picturebox.paint事件调用抽签例程之后发生的。如果我再次调用绘图例程(在本例中是由Spectra_MouseUp引起的),则图像将被完全重绘。

回到窗口后,我想不出如何保存(或重绘)整个图像。

我的代码的相关部分如下:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-22 19:25:29

谢谢克里斯。结果是使用Spectra.CreateGraphics而不是PaintEventArgs (对于e.Graphics)才是问题所在。我重新做了下面的工作&它现在工作得很好。

代码语言:javascript
复制
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 Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23790689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档