我有一个包含组合框、文本框和多行数据网格的表单。我想打印出来(使用生成的条形码[应用程序生成条形码作为图像]),并且还想将该页面中的数据以 CSV/XML/Excel 格式导出到 USB 或手机的物理目录。请指导我如何去做。这是我的第一个 Windows Mobile 应用程序。我在 Windows Mobile 中并不那么聪明。请帮助我找到更好的解决方案作为代码或链接,或者直接指导我。
问问题
2349 次
1 回答
0
要创建打印输出,您必须使用 GDI 写入 PrintDocument。没有什么真正内置的。你可以做一个截图(下面的代码)。
将数据导出到 CSV 最好也由您自己完成。只需创建/打开一个文件流并写入您想要的任何内容。
屏幕截图:需要 PInvoke 到 BitBlt 和 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
最后,如果您想
Bitmap
在内存中使用它,只需保存它并根据需要使用它。例子:panel1.Image = ScreenCapture("image.png"); panel1.BringToFront();
希望有帮助。
于 2011-10-19T14:27:33.317 回答