Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

c# - Print and Export to USB (File Format: XML/CSV/Excel) Functionality in Smart device[Symbo Motoroal MC75(Windows Mobile 6.1)] application?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. \WindowsTempscreenShot.png).

  • 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.

  • 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...