Solved

GDI+ Question

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

10 Experts available now in Live!

Get 1:1 Help Now