Solved

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

Posted on 2006-11-06
5
194 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now