My program is supposed to draw a red rectangle around itself, wich it does fine. However each time it redraws it leaves behind red marks.
I have tryed Invalidating the desktop (the whole screen), wich only made it worse. (Becuase it made my program redraw, wich left even more marks)
Any suggestions?
Heres my code.
I have tryed Invalidating the desktop (the whole screen), wich only made it worse. (Becuase it made my program redraw, wich left even more marks)
Any suggestions?
Heres my code.
VB.NET:
Sub UpdateLoc()
Dim us As Process = Process.GetCurrentProcess()
Dim struct As New RECT
GetWindowRect(us.MainWindowHandle, struct)
FormRect = struct.ToRectangle
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim hdc As IntPtr = GetDC(IntPtr.Zero)
Dim p As New Pen(Color.Red, 4)
UpdateLoc()
Try
' Get the graphics object for the desktop window
Dim g As Graphics = Graphics.FromHdc(hdc)
Try
' Draw a red rectangle around a program (Currently this one)
g.DrawRectangle(p, FormRect)
Finally
' Dispose the graphics object, failing to do this will cause system instability
g.Dispose()
End Try
Finally
' Release the handle to the desktop window, again, failing to do this is a bad idea.
ReleaseDC(IntPtr.Zero, hdc)
End Try
End Sub