• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

How can you draw using gdi on the screen instead of a control ?


I want to draw some lines on a panel, but the lines always appear behind any of the controls on the panel.
I want to be able to draw over the controls (if possible) ?

thanks in advance,
0
Kinger247
Asked:
Kinger247
  • 2
  • 2
1 Solution
 
VoteyDiscipleCommented:
Well, the most direct thing I can think is to draw on a control that sits on top of the controls, perhaps with a transparent background?  If you draw on, say, the form background, .NET is pretty smart about showing and hiding things based on where controls are.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can draw on the desktop itself:

    Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr
    Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As IntPtr, ByVal hdc As Integer) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim desktopHwnd As IntPtr = GetDesktopWindow()
        Dim desktopHdc As IntPtr = GetWindowDC(desktopHwnd)
        Dim g As Graphics = Graphics.FromHdc(desktopHdc)

        ' draw with "g" here...
        ' (Remember to use SCREEN coordinates)

        g.Dispose()
        ReleaseDC(desktopHwnd, desktopHdc)
    End Sub
0
 
Kinger247Author Commented:
How do you clear any drawings if they're being moved ?
So on a control you would invalidate. But how can you do that to a screen ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are drawing directly above your form then you can refresh the form and that will "erase" the desktop because the form redraws itself.

If you want a more targeted refresh then use the Invalidate() method:
http://msdn2.microsoft.com/en-us/library/8bk29t0f(VS.80).aspx
0
 
Kinger247Author Commented:
Looks like I have some work to do .. ;)
Thanks Idle_Mind.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now