Solved

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

Posted on 2006-11-06
5
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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 86

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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