Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:24:21+00:00 2026-05-11T11:24:21+00:00

I am using the following code to draw on a single monitor: Point cursorLocation;

  • 0

I am using the following code to draw on a single monitor:

Point cursorLocation; NativeMethods.GetCursorPos(out cursorLocation); Screen screen = Screen.FromPoint(cursorLocation);  Point h1 = new Point(screen.Bounds.Left, cursorLocation.Y); Point h2 = new Point(screen.Bounds.Right, cursorLocation.Y); Point v1 = new Point(cursorLocation.X, screen.Bounds.Top); Point v2 = new Point(cursorLocation.X, screen.Bounds.Bottom);  using (Graphics graphics = Graphics.FromHwnd(NativeMethods.GetDesktopWindow())) {     NativeMethods.SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);     graphics.DrawLine(Pens.Red, h1, h2);     graphics.DrawLine(Pens.Red, v1, v2); } 

Natively, this should theoretically draw on either monitor. However, it only draws on the primary. So, to fix this I am getting the DC of all the displays and trying to do it this way.

IntPtr hdc = NativeMethods.CreateDC('DISPLAY', IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); Graphics graphics = Graphics.FromHdc(hdc); graphics.DrawLine(Pens.Red, h1, h2); graphics.DrawLine(Pens.Red, v1, v2); graphics.Dispose(); NativeMethods.ReleaseDC(IntPtr.Zero, hdc); 

Go figure, this doesn’t even draw to the screen at all. I have tried various overloads for CreateDC, as well as searched SO and other resources and I’m stumped.


Once this is resolved, anyone know how to get rid of flicker by refreshing the desktop using SHCHangeNotify? I’m only drawing two lines and it flickers like mad..)

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:24:22+00:00Added an answer on May 11, 2026 at 11:24 am

    This is not an answer to your question but if you have no problem with it, I would recomment trying using WPF to solve this. I have played with other kind of desktop interaction like transparency and WPF is lightning fast compared to the GDI alternative.

    You place your wpf application and resize it to fit all the area you need to be painting on. Then set it to transparent, and make sure its clickthrough (i think that is default on 100% transparency). That way as long as you dont have anything on this big WPF canvas/form all mouse events will click through to desktop.

    Then just start painting on it. (i liked it because it was very easy to add effects to lines and images). Guaranteed no flickering.

    Alternatively you could use the same scheme on normal Windows Forms instead.

    This way you wont have to turn to GDI to do your work.

    I think the only way you would be able to do this flickerfree as you are approaching it now, would be to hook into the window messaging on the desktops WM_PAINT and do your work there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating date using following code try { newdatetime = new DateTime(2012, 2,
I'm using the following code to draw a green line at some specified coordinates
I'm using the following code to draw an SVG text box, and then change
I can draw a hyperlinked shape in tikz using the following code: \documentclass{article} \usepackage{tikz}
I am using the following code and it draws a triangle on the screen.
I am using the following code to draw Strings. In GDI+ Graphics tempFontGr(XXX); Matrix*
I want to draw some sort graphics on winform using following code : private
i am using following code to draw canvas and save it as png image
I'm using the following code to draw plots of two different data on same
I am using the following code to draw a graph and print it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.