tform.print for windows lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- mas steindorff · 2010-09-06 22:53 Before I sit down and write a new object that will print the UI of a form, is there already one out there?  I'm working in widows when I worked in D5, all I needed to do was Tform.Print as a quick print option. I've found some code in the microsoft on how to do the system calls but I will like an object I can just add and call. ---------------------------------------------------------------------- theo · 2010-09-07 08:31 You could take a screenshot of the form's canvas and the print the bitmap. Bitmap.LoadFromDevice(Form1.Canvas.Handle); At least on GTK2 this works, not tested on Win. ---------------------------------------------------------------------- mas steindorff · 2010-09-08 00:49 I've got some simple code working with bitmap.loadFromDevice and Tprinter objects. (thanks for the hint theo) the loadFromDevice(form1.canvas.handle) only gives me the form and it's contents.  I do not get the form's title bar in windows.  that is not a show stopper however, I got what I needed.  It's interesting to note that all I needed to do to select a printer was to pop a printdialog on the form and run   PrintDialog1.Execute.  The selected printer is automatically picked up by the printer object ---------------------------------------------------------------------- Leledumbo · 2010-09-08 05:26 Quotethe loadFromDevice(form1.canvas.handle) only gives me the form and it's contents.  I do not get the form's title bar in windows.Easy to fix, take a look at this thread: http://forum.lazarus.freepascal.org/index.php/topic,8989.0.html ---------------------------------------------------------------------- mas steindorff · 2010-09-08 17:26 Quote from: Leledumbo on September 08, 2010, 07:26:18 amQuotethe loadFromDevice(form1.canvas.handle) only gives me the form and it's contents.  I do not get the form's title bar in windows.Easy to fix, take a look at this thread: http://forum.lazarus.freepascal.org/index.php/topic,8989.0.html I tried this code and got the same results (more or less).  here is what I used to test it Code: [Select]procedure PrintForm2(frm:TForm); var   MyBitmap, : TBitmap;   MyDC: HDC; begin    MyBitmap := TBitmap.Create;    try      MyDC := GetDC(frm.Handle);      try        MyBitmap.LoadFromDevice(MyDC);        MyBitmap.SaveToFile('ImageAndPanel.bmp');      finally        ReleaseDC(0, MyDC);      end;    finally      FreeAndNil(MyBitmap);     end; end; I think the Key is the  GetDC() command.  I can change it's parameters to select the full screen and then use the form's location to strip away the rest.  that's the reference I got from Microsoft.  I sill tend to what to use theo's trick as it may be cross platform friendly even though I don't need it to be. In the end, I'll probably use both. ---------------------------------------------------------------------- mas steindorff · 2010-09-08 17:36 ... at least that was what I was thinking . How do you get the contents of the 2nd or a 3rd screen with GetDC?  0 will grab the 1st screen