Solved

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

Posted on 2006-11-06
5
193 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Looks like I have some work to do .. ;)
Thanks Idle_Mind.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

16 Experts available now in Live!

Get 1:1 Help Now