DllImport problem

G

gsb58

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)
 
J

Jon Skeet [C# MVP]

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")]

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
 
G

gsb58

Yes, thank you. Now it works like :)


Jon Skeet [C# MVP] skrev:
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")]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top