在任务栏上绘制图像时 Winforms 闪烁

发布于 2024-09-17 21:09:25 字数 849 浏览 3 评论 0原文

现在我正在窗口的标题栏上绘制一个 16x16 的小图像。它工作得很好,除了令人讨厌的闪烁,我不知道如何消除它。

我只是像这样绘制图像:

Protected Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_SIZE Then
        wnd_size = New Size(New Point(CInt(m.LParam)))
    End If
    If m.Msg = WM_ACTIVATE _
    OrElse m.Msg = WM_SIZE _
    OrElse m.Msg = WM_SYNCPAINT _
    OrElse m.Msg = WM_NCACTIVATE _
    OrElse m.Msg = WM_NCCREATE _
    OrElse m.Msg = WM_NCPAINT _
    OrElse m.Msg = WM_NCACTIVATE _
    OrElse m.Msg = WM_NCHITTEST _
    OrElse m.Msg = WM_PAINT _
    OrElse m.Msg = WM_MOUSEMOVE Then
        Dim g As Graphics = Graphics.FromHdc(CType(GetWindowDC(CInt(Handle)), IntPtr))
        g.DrawImage(My.Resources.drag, 0, 0, 16, 16)
    End If
    MyBase.WndProc(m)
End Sub

每次在其上进行更改(单击、将鼠标悬停在角按钮上等)时,它都会重新绘制整个标题栏,并且在重新绘制期间我会闪烁。

还有其他人遇到过这个问题吗?

Right now I'm drawing a small 16x16 image on the title bar of my window. It works nicely, except for an obnoxious flicker that I cant figure out how to get rid of.

I'm simply drawing the image like this:

Protected Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_SIZE Then
        wnd_size = New Size(New Point(CInt(m.LParam)))
    End If
    If m.Msg = WM_ACTIVATE _
    OrElse m.Msg = WM_SIZE _
    OrElse m.Msg = WM_SYNCPAINT _
    OrElse m.Msg = WM_NCACTIVATE _
    OrElse m.Msg = WM_NCCREATE _
    OrElse m.Msg = WM_NCPAINT _
    OrElse m.Msg = WM_NCACTIVATE _
    OrElse m.Msg = WM_NCHITTEST _
    OrElse m.Msg = WM_PAINT _
    OrElse m.Msg = WM_MOUSEMOVE Then
        Dim g As Graphics = Graphics.FromHdc(CType(GetWindowDC(CInt(Handle)), IntPtr))
        g.DrawImage(My.Resources.drag, 0, 0, 16, 16)
    End If
    MyBase.WndProc(m)
End Sub

Its repainting the entire title bar each time something is changed on it(click, mouseover the corner buttons, etc), and its during the repaint I get the flicker.

Anyone else ever get this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2024-09-24 21:09:25

根据之前对此的评论,我认为它并不值得追求。除非我完全手动绘制标题栏,否则闪烁效果不会消失,这是一个笨拙的解决方法。相反,我重新思考了如何处理整个程序。唯一可行的解​​决方案是完全删除窗口边框并在表单顶部绘制伪边框/栏。请参阅http://www.codeproject.com/KB/miscctrl/gTitleBar.aspx

或者更好的是,就保留标题栏即可。

In light of previous comments on this, I've decided that its not really worth pursuing. The flicker effect wont go away unless I completely draw the title bar manually, which is a clunky workaround. Instead I've redone my thinking on how to handle the program in its entirety. The only viable solution is to completely remove the windows border and draw a psuedo border/bar on top of the form. See http://www.codeproject.com/KB/miscctrl/gTitleBar.aspx

Or better yet, just let the title bar be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文