Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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
Posted
Updated 17-Mar-11 8:32am
v3
Comments
Sergey Alexandrovich Kryukov 17-Mar-11 14:35pm    
Not enough information. Where is your code?
--SA
Sergey Alexandrovich Kryukov 17-Mar-11 14:37pm    
Right, what you attempted to fix would not help. You need to show your OnPaint.
--SA
Henry Minute 17-Mar-11 15:14pm    
In addition to the code, it might help if you describe what 'it trashes the text and lines I've drawn' means. Are you able to describe in what way it gets trashed?
Phil Diver 17-Mar-11 16:09pm    
I mistakenly added "as a solution" - sorry.

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900