Solved

GDI+ Question

Posted on 2004-10-11
3
214 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 500 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

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

18 Experts available now in Live!

Get 1:1 Help Now