VB NET自定义控件在没有重点关注时会被破坏 [英] VB NET Custom Control trashes when not focused

查看:82
本文介绍了VB NET自定义控件在没有重点关注时会被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个VB NET自定义控件-一个带有一些文本的简单图形.

在其上拖动另一个窗口会浪费我绘制的文本和线条.
我正在使用Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)绘制文本和线条,并且在聚焦时,该控件显示正常.

在未聚焦的情况下如何拖动垃圾箱,并在其上拖动另一个窗口?

这些似乎无能为力:
''g.Flush() doesn''t help
''MyBase.OnPaint(e) doesn''t help

I''ve created a VB NET Custom Control - a simple graph with some text.

Dragging another window over it trashes the text and lines I''ve drawn.
I''m using Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) to paint the text and lines, and while focused, the control displays fine.

How do I prevent the trashing while it''s not focused and I drag another window over it?

These seem to do nothing:
''g.Flush() doesn''t help
''MyBase.OnPaint(e) doesn''t help

推荐答案

下面是在图片上拖动另一个窗口之前和之后的照片:
http://phactor.com/t.gif

我的代码:
Here is a pic before and after dragging another window over it:
http://phactor.com/t.gif

My code:
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim r As System.Drawing.Rectangle = e.ClipRectangle
        Dim g As Graphics = e.Graphics
        Dim p As New Pen(Color.White)
        Dim hFont As IntPtr = GetStockObject(17)
        Dim hFFont As Font = Font.FromHfont(hFont)
        g.Clear(Color.FromArgb(80, 80, 80))
...  code that paints my text and lines
        g.Dispose()
    End Sub


这篇关于VB NET自定义控件在没有重点关注时会被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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