在任务栏上绘制图像时 Winforms 闪烁
现在我正在窗口的标题栏上绘制一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据之前对此的评论,我认为它并不值得追求。除非我完全手动绘制标题栏,否则闪烁效果不会消失,这是一个笨拙的解决方法。相反,我重新思考了如何处理整个程序。唯一可行的解决方案是完全删除窗口边框并在表单顶部绘制伪边框/栏。请参阅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.