在智能设备[Symbo Motoroal MC75(Windows Mobile 6.1)]应用程序中打印并导出到USB(文件格式:XML/CSV/Excel)功能吗? [英] Print and Export to USB (File Format: XML/CSV/Excel) Functionality in Smart device[Symbo Motoroal MC75(Windows Mobile 6.1)] application?
问题描述
我有一个包含组合框,文本框和多行数据网格的表单.我要打印出来(使用生成的条形码[应用程序将条形码作为图像生成应用程序]),还希望将该页面中的数据以CSV/XML/Excel格式导出到USB或电话的物理目录中.请指导我如何做.这是我的第一个Windows Mobile应用程序.我在Windows Mobile中不是那么明智.请帮助我找到更好的解决方案作为代码或链接,或者直接指导我.
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.
推荐答案
要创建打印输出,您将必须使用GDI写入PrintDocument.真正没有内置任何功能.您可以做一个屏幕截图(下面的代码).
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).
将数据导出到CSV最好也自己完成.只需创建/打开文件流,然后将其写入即可.
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.
屏幕截图:需要PInvoke才能访问BitBlt和GetDC
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;
}
[更新]:
-
如果要将图像保存到特定位置,请发送完整路径和文件名(即
\\Windows\Temp\screenShot.png
).
如果要排除控件,请减小this.Width
,this.Height
,this.Left
和this.Right
,直到您具有适合工作区域的大小为止.
If you want to exclude the controls, reduce the this.Width
, this.Height
, this.Left
and this.Right
until you have the size that fits the region that works.
最后,如果要在内存中使用Bitmap
,只需保存并根据需要使用即可.示例:
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();
panel1.Image = ScreenCapture("image.png"); panel1.BringToFront();
希望有帮助.
这篇关于在智能设备[Symbo Motoroal MC75(Windows Mobile 6.1)]应用程序中打印并导出到USB(文件格式:XML/CSV/Excel)功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!