How to protect drawing on screen ?

itman21c

New member
Joined
Jan 19, 2007
Messages
1
Programming Experience
Beginner
Hi. All

I am newbie and I am trying to draw something to screen directly.
I made following code.
VB.NET:
Dim hScreenDC As IntPtr = GetWindowDC(IntPtr.Zero)
Dim dPen As New Pen(Color.Red, 5)
       GR = Graphics.FromHdc(hScreenDC)
       Using GR
               GR.DrawLine(dPen, 100, 100, 500, 500)
       End Using
ReleaseDC(IntPtr.Zero, hScreenDC)

I could draw a line on screen but when I open some window or popup and so on, the drawing is cleared as window size.

Is there any way to protect screen drawing from other window ?
 
Try This:
VB.NET:
Public Class Form1
    Dim G As Graphics
    Dim Dpen As New Pen(Color.Red, 5)

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        G = e.Graphics
        G.DrawLine(Dpen, 100, 100, 500, 500)
    End Sub
End Class

P.S. to "protect screen drawing from other window" you need to put the code in the paint event.
 
Back
Top