Solved

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

Posted on 2006-11-06
5
197 Views
Last Modified: 2010-04-23

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
Comment
Question by:Kinger247
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17881388
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17881601
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
 
LVL 10

Author Comment

by:Kinger247
ID: 17881654
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17881693
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
 
LVL 10

Author Comment

by:Kinger247
ID: 17881715
Looks like I have some work to do .. ;)
Thanks Idle_Mind.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question