?
Solved

GDI+ Question

Posted on 2004-10-11
3
Medium Priority
?
222 Views
Last Modified: 2010-04-23
Does anyone know how to draw on the desktop?  Not on a form.  Let's say for example, how would you draw the following line?

Start the line at the form's left edge (y-axis doesn't matter) and draw the line to the left (in other words, off the form and across the desktop).

Please help.

Thanks in advance.
0
Comment
Question by:jrandallsexton
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 2000 total points
ID: 12286581
Hi jrandallsexton,

You could try one of these things,

1. With API

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As IntPtr) As IntPtr
        Dim deskDC As IntPtr = GetDC(IntPtr.Zero)
        Dim g As Graphics = Graphics.FromHdc(deskDC)
        g.DrawLine(New Pen(Color.Black), 0, 0, 300, 300)

2. With the Controlpaint class

        Dim p1 As New Point(0, 0)
        Dim p2 As New Point(300, 300)
        ControlPaint.DrawReversibleLine(p1, p2, Color.Black)

0
 
LVL 4

Author Comment

by:jrandallsexton
ID: 12286603
I haven't tried #1 but #2 works.  I've never heard of ControlPaint.  I'm going to do some reading (a lot actually) on that.

I think you've pointed me in exactly the direction I needed.  Thanks.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12286688
Hi Jrandallsexton,

Its a very cool class you can draw entire datagrids with that, if you combine method 1 and 2, you can even do that on the desktop.

Sorry I forgot one thing for the first method don't forget to release the dc aswell, otherwise you will run out of memory.

Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As intptr
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

840 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