PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Printing with CF
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Printing with CF
![]() |
Printing with CF |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello,
I'm trying to print from an CF-Application on an usb-printer. I can print a screenshot on the printer by using some API-Functions. But now I'm trying to print my own Graphic (All Data of an DataTable; the result should look like a datagrid). I've been starting with this code: DEVMODE dm = new DEVMODE(); dm.dmSize = System.Convert.ToInt16(Marshal.SizeOf(dm)); dm.dmOrientation = (Int16)PageOrientation.DMORIENT_LANDSCAPE; dm.dmPrintQuality = DMRES_DRAFT; //IntPtr hPrinterDC = CreateDC(null, "PCL Inkjet", null, ref dm); IntPtr hPrinterDC = CreateDC("pcl.dll", "PCL Inkjet", "LPT2", ref dm); // --- 2--- mit DeviceContext Dokument Starten //DOCINFO di = new DOCINFO(); //di.cbSize = Marshal.SizeOf(di); //di.fwType = 0; //di.lpszDocName = IntPtr.Zero; // Marshal.StructureToPtr(@"\printdocument.txt", true); //di.lpszOutput = IntPtr.Zero;// Marshal.StructureToPtr(@"\printdocument.prn", true); //di.lpszDataType = IntPtr.Zero; //di.fwType = 0; String lpszDocName = @"\Image.bmp"; String lpszOutput = @"\Image.prn"; String lbszDataType = ""; int cbMemSize = 20 + GetStringAllocSize(lpszDocName) + GetStringAllocSize(lpszOutput) + GetStringAllocSize(lbszDataType); IntPtr p = LocalAlloc(0x40, cbMemSize); DOCINFO di = new DOCINFO(); di.cbSize = 20; di.fwType = 0; di.lpszDocName = new IntPtr(p.ToInt32() + 20); di.lpszOutput = new IntPtr(di.lpszDocName.ToInt32() + GetStringAllocSize(lpszDocName)); di.lpszDataType = IntPtr.Zero; Marshal.StructureToPtr(lpszDocName, di.lpszDocName, false); //Marshal.StructureToPtr(lpszOutput, di.lpszOutput, false); if (StartDoc(hPrinterDC, ref di) > 0) { //--- 3 --- Graphic von Hdc erzeugen //Graphics g = Graphics.FromHdc(hPrinterDC); //--- 4 --- draw eg. a Text g.DrawString("Hallo!", new Font("Arial", 20, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(20, 20, 20, 20)); //--- 5 --- StartPage StartPage(hPrinterDC); //TODO scale //--- 6 --- EndPage EndPage(hPrinterDC); //--- 7 --- EndDocument EndDoc(hPrinterDC); //--- 8 --- CleanUp g.Dispose(); } DeleteDC(hPrinterDC); The printer put's a sheet of paper, but doesn't print anything. I also tried the following instead of g.DrawString (...) String str = "Hello World!"; TextOut(hPrinterDC, 50, 140, 0, IntPtr.Zero, str, (ushort)str.Length, IntPtr.Zero); But this didn't work either. What's wrong with my code? does anyone has an other idea? Many thanks in advance, Sabine |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

