Sign in to follow this  

[.net] get HDC from usercontrol object?

This topic is 3574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to get the HDC of a System::Windows::Forms::UserControl object. All I've found so far is a Handle that's a IntPtr and won't work for the dll function I need to call.

Share this post


Link to post
Share on other sites
How about something like this:
using(Graphics g = this.CreateGraphics())
{
IntPtr hdc = g.GetHdc();

// use it here...
}

If it's in an OnPaint method, you don't need to do CreateGraphics(); you can just use the Graphics property of the PaintEventArgs object.

Share this post


Link to post
Share on other sites
Ok, this is how I got it working.

HWND hWnd = (HWND)this->Handle.ToInt32();
hDC = GetDC(hWnd);



Maybe someday I'll get the hang of this .NET stuff...

Share this post


Link to post
Share on other sites

This topic is 3574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this