By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,154 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,154 IT Pros & Developers. It's quick & easy.

Device contexts

P: n/a
Hi
Does anybody have any code examples of using C# to draw to a window using
device contexts, more specifically, erasing the entire window by painting a
background color in the OnPaint / OnDraw event? What about using a buffer
device context to draw to, then BitBlt ing that to the screen?
Thanks
Ben
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanks, I have tried this before, but for the life of me I couldn't get it
to work - I've never used C# before and it seems like a really good
language, it's just that whenever I tried to use the Graphics object to
paint a white rectangle the size of the entire form, it still showed what
was previously there. I just wondered if anyone had some sample code I could
model what I want to do on. Never mind.

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2***************@tk2msftngp13.phx.gbl...
Ben,

There are managed representations for almost everything you mention
here.

If you want to draw to a window, then when you override the OnPaint
method, you can use the Graphics instance passed in to draw on the device
context. If you have other functions which take a device context handle,
then you can call the GetHdc method to get a handle you can pass to
unmanaged code to do your drawing.

If you want to double buffer your calls in OnPaint, then you can call
the SetStyle method, passing in the following values (or'ed together) on
your class:

ControlStyles.UserPaint
ControlStyles.AllPaintingInWmPaint
ControlStyles.DoubleBuffer

The control will then be responsible for creating the other device
context and BitBlt'ing it back to the original device context.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"Ben Taylor" <be***********@yahoo.co.uk> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl...
Hi
Does anybody have any code examples of using C# to draw to a window using device contexts, more specifically, erasing the entire window by painting
a
background color in the OnPaint / OnDraw event? What about using a

buffer device context to draw to, then BitBlt ing that to the screen?
Thanks
Ben


Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.