471,336 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

DllImport problem

Hi!

On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

private const Int32 SRCCOPY = 0xCC0020;

private Bitmap memImage;

private void PrepareImage()
{
Graphics graphic = kalle.CreateGraphics();
Size s = this.Size;
memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, kalle.ClientRectangle.Width,
kalle.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
}

However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?

Me.Name
(Just took the MCP-cert. on SQL-Server 2000)

Jan 13 '06 #1
2 8491
gs***@hotmail.com wrote:
On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]
<snip>
However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?


You need to add:

using System.Runtime.InteropServices;

to your class. I haven't looked at the rest of your code though.

Jon

Jan 13 '06 #2
Yes, thank you. Now it works like :-)
Jon Skeet [C# MVP] skrev:
gs***@hotmail.com wrote:
On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]


<snip>
However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?


You need to add:

using System.Runtime.InteropServices;

to your class. I haven't looked at the rest of your code though.

Jon


Jan 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Jim | last post: by
1 post views Thread by Whidbey Wave | last post: by
2 posts views Thread by Brian Anderson | last post: by
1 post views Thread by Seth Gecko | last post: by
1 post views Thread by mrssuper | last post: by

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.