473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Device contexts

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
1 2950
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tech.witch | last post by:
I'm doing a postmortem from an outage at my workplace that looks too similar to an outage we had last fall to not be related. Both database outages had the following characteristics: 1) VERY...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
12
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
8
by: Tony Liu | last post by:
I am having a "Null Device is Missing" compile error when compiling a c++ project. The documentation from MSDN said it could be caused by low system resource or the user account does not have...
7
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
2
by: Rosalind Chen | last post by:
Hi, This is the first time that I use Visual Studio .NET. And I stucked in this first problem. - I created a SDK from Platform builder 4.2 that includes .Net Compact Framework. - installed...
0
by: Shival | last post by:
Hi, I have a Device that will be used by dentist to take their paitient teaath pics. this Device is having a click button from which the device takes pics. The Device is configured to my OS...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
6
by: =?Utf-8?B?bmNvbG9zaQ==?= | last post by:
Is it possible to render a winform directly to a memory device context instead of rendering to a display device context ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.