Winforms在任务栏上绘制图像时闪烁 [英] Winforms Flickering While Drawing Image on Taskbar

查看:123
本文介绍了Winforms在任务栏上绘制图像时闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在窗口标题栏上绘制一个16x16的小图像.它工作得很好,除了我无法弄清楚如何摆脱的令人讨厌的闪烁.

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?

推荐答案

鉴于先前对此的评论,我认为它确实不值得追求.除非我手动完全绘制标题栏,否则闪烁效果不会消失,这是一个笨拙的解决方法.取而代之的是,我重新思考了如何完整地处理该程序.唯一可行的解​​决方案是完全删除窗口边框,并在表单顶部绘制伪边框/条.请参见 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.

这篇关于Winforms在任务栏上绘制图像时闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆