-2

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.

Smi
  • 13,850
  • 9
  • 56
  • 64
code_star_net
  • 213
  • 7
  • 23

1 Answers1

0

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

  • very Thanks For Your Reply...i am completely new to this.i just want to know tat,wher it will save this image?i want to write the content from data set to this image...and save it in physical memory. – code_star_net Oct 20 '11 at 05:55
  • Hi ,Actually it showing all the Control and button in the generated image.can u please send me the code/link to print this image...in windows mobile 6[motorola mc75] either blutooth or usb... – code_star_net Oct 20 '11 at 06:05
  • Thanks For your Great Help Friend.and i need to know,In My datagrid there is more than 50 rows .can i get all this row in this screen shot image[bcoz datagrid is set to scrolling and its only showing someroes at top]..how to iterate thru datagrid and save each row as image....and one more ...can i get coonect windows mobile 6 with bluetooth [how to find bluetooth printer device and get its mac id in c#] Waitng for u reply...i hope u can help me to find it.... – code_star_net Oct 21 '11 at 05:10
  • For something like that, you'd have to write a custom routine. The screen capture will only capture what is shown on the screen. –  Oct 21 '11 at 13:03