• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1052
  • Last Modified:

BitBlt of picturebox

I have 2 pictures box.  One already got a bitmap loaded, and i would like to try to do a copy with BitBlt.  I know that there's probably already a function to do that, but i'm trying to test the performance of a bitblt in c# thru pinvoke vs c++.

How do i get the HDC of the picture boxes?

Christian de Bellefeuille
Christian de Bellefeuille
3 Solutions
Luis PérezSoftware Architect in .NetCommented:
Check this, I think this is what you're looking for.


Hope that helps.
Mohamed AbowardaSoftware EngineerCommented:
You need to use GetDC API to get the picturebox hDC:

1. Add the line "using System.Runtime.InteropServices;" above the namespace
2. Add the following line to your form class:
    public static extern IntPtr GetDC(IntPtr hWnd);

3. Use the following code to get the picturebox hDC
IntPtr hDC = GetDC(pictureBox1.Handle);

Open in new window

Christian de BellefeuilleProgrammerAuthor Commented:
Thanks a lot Medo, it work just fine!
Mike TomlinsonMiddle School Assistant TeacherCommented:
...be sure to use ReleaseDC() to prevent GDI leaks.
Mohamed AbowardaSoftware EngineerCommented:
You are very welcome :)

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now