Solved

GDI+ Question

Posted on 2004-10-11
3
219 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
[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
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

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