Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug GDI+ in c#?

Tags:

c#

gdi+

drawing

i have a user control, and it's not drawn correctly, how to debug the drawing? If i set break point, the control will get blocked, i can't see the drawing result instantly? any idea?

like image 388
Benny Avatar asked Oct 17 '25 13:10

Benny


2 Answers

What you need is the Graphics Debugger visualizer.

like image 198
Kris Erickson Avatar answered Oct 20 '25 04:10

Kris Erickson


It's best to debug drawing activities with a multi-monitor setup, but there are a handful of other things that can help if you've only got one monitor.

  1. Repositioning your IDE (Visual Studio) so that it doesn't overlap. Unfortunately, this may not help if you need active focus on the control.
  2. Draw a 2nd copy into a bitmap, and write the bitmap to disk or redisplay it in a dialog or some other window. This is a bit of extra work, but conceptually the same as doing logging.
  3. Alter your drawing code so that certain elements or certain parts of elements are only drawn if you have certain keys pressed down (left-shift/right-shift, ctrl, alt, or some combination of those keys). This is easy to add and can allow you to filter out parts of your code that would be tricky to step into with the debugger.

Here's the function that can provide the state for you (requires p/invoke) and the signature from pinvoke.net.

GetKeyState Function() @ MSDN
pinvoke.net: GetKeyState (user32)

like image 35
meklarian Avatar answered Oct 20 '25 02:10

meklarian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!