问题
I have a form which contains combo boxes, textboxes and a data grid with many rows. I want to take print out (with generated barcode [application generating barcode as image]) and also want to export the data in that page as CSV/XML/Excel format to USB or Phone's Physical Directory. Please guide me how to it. This is my first Windows Mobile app. I am not so wise in Windows Mobile. Please help me find a better solution as a code or link or just direct me.
回答1:
To create the Print Out, you will have to write to your PrintDocument using GDI. There is nothing really built in. You could possibly do a screenshot (code below).
Exporting data to CSV is best done on your own as well. Just Create/Open a file stream and write whatever you want to it.
Screenshot: Requires PInvoke to BitBlt and GetDC
const int SRCCOPY = 0x00CC0020;
[DllImport("coredll.dll")]
private static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
public Bitmap ScreenCapture(string fileName) {
Bitmap bitmap = new Bitmap(this.Width, this.Height);
using (Graphics gScr = Graphics.FromHdc(GetDC(IntPtr.Zero))) { // A Zero Pointer will Get the screen context
using (Graphics gBmp = Graphics.FromImage(bitmap)) { // Get the bitmap graphics
BitBlt(gBmp.GetHdc(), 0, 0, this.Width, this.Height, gScr.GetHdc(), this.Left, this.Top, SRCCOPY); // Blit the image data
}
}
bitmap.Save(fileName, ImageFormat.Png); //Saves the image
return bitmap;
}
[Update]:
If you want the image saved to a particular location, send the full path with the filename (i.e.
\\Windows\Temp\screenShot.png
).If you want to exclude the controls, reduce the
this.Width
,this.Height
,this.Left
andthis.Right
until you have the size that fits the region that works.Last, if you want the
Bitmap
to use in memory, simply save it and use it as necessary. Example:panel1.Image = ScreenCapture("image.png"); panel1.BringToFront();
Hope that helps.
来源:https://stackoverflow.com/questions/7817689/print-and-export-to-usb-file-format-xml-csv-excel-functionality-in-smart-devi