Printing Form

Posted on 2000-03-03
Last Modified: 2010-04-04
How to prevent components eg buttons on a form from being printed? Any help is greatly appreciated.
Question by:zulhilmi
LVL 17

Expert Comment

ID: 2581343
5 points isnt much appreciation ...

Expert Comment

ID: 2581622
before you start printing make them invisible

Expert Comment

ID: 2585469
Why?  What are you trying to accomplish?

Mark Rissmann

Accepted Solution

zb_russia earned 5 total points
ID: 2590945
Can take advantage of my experience (seal of tables, graphs, images etc.). This my answer is included in Russian faq on Delphi. I give back so, as for this work it is necessary to take not less than 400-500 numbers.

How correctly to print any information (raster and vectorial images),
And also how to make a condition of preliminary survey?

   Small preface.

Since basic mine of work is connected to a spelling soft for institute, manufactured geodatas, and in a department, where working, as are tormented problems of a seal (in one case - it is necessary to print map, with isoline, having fill., subscripts and other; in other a case - tables and complicated painting on appearance).
In a result, my colleague wrote a piece, in which he managed to achieve a qualitative seal in two of regims: MetaFile, Bitmap.
The work with MetaFile at us has developed already hystorycal - rather conveniently to describe function, which something of paint (though on screen, though where), which get TCanvas, and to palm off on her that canvas of the display, êàíâàñ metafile, and then this of Metafile put on a seal.
There is enough solve only problem scaling, then - forward.

Principal head pain at such method - painting of large pieces, which take the whole sheet or his majority, it is necessary this metafile on size to do at once in pixels on this sheet. Then at a modification size (preview by a seal) - distortion a diminution not critical, and here at magnification of a line and font not "creep".


List of ideas, which were written (ñ) Andrew Aristov , programmer of a department of a software SibNIINP, Tyumen. Mine here only - attach from above settings for personal use.

All of work is reduced to the following pitches:

1. To receive necessary coefficents.
2. Construct metafila or bmp for a consequent conclusion on a seal.
3. Print.

Lower sample a piece (please me not beat, but was written by I and I wrote for enough curve realization with passing parameters over global variables) I use to receive coefficients of recalculation.

KScale - for recalculation size font, and then I are already pawned on it of size and I receive two new coefficients for kW, kH - which and the heights fonts allow me with allowance for to remove graphics and other. At me of work kW < > kH, that come to take into account.

Have decided an item 1.

procedure SetKoeffMeta; // set coefficient
  PrevMetafile : TMetafile;
  MetaCanvas : TMetafileCanvas;
  PrevMetafile  :=  nil;
  MetaCanvas    :=  nil;
    PrevMetaFile  :=  TMetaFile.Create;
      MetaCanvas  :=  TMetafileCanvas.Create( PrevMetafile, 0 );
      kScale := GetDeviceCaps( Printer.Handle, LOGPIXELSX ) / Screen.PixelsPerInch;
      MetaCanvas.Font.Assign( oGrid.Font);
      MetaCanvas.Font.Size := Round( oGrid.Font.Size * kScale );
      kW := MetaCanvas.TextWidth('W') /  oGrid.Canvas.TextWidth('W');
      kH := MetaCanvas.TextHeight('W') / oGrid.Canvas.TextHeight('W');

Have decided an item 1.

  PrevMetafile : TMetafile;
  MetaCanvas : TMetafileCanvas;
  PrevMetafile  :=  nil;
  MetaCanvas    :=  nil;

    PrevMetaFile  :=  TMetaFile.Create;

    PrevMetafile.Width  :=  oWidth;
    PrevMetafile.Height :=  oHeight;

      MetaCanvas  :=  TMetafileCanvas.Create( PrevMetafile, 0 );

      // Here there should be your code - with allowance for scaling.
      // I have born this thing in assigned procedure, and given block
      // I call only for painting whole page.

      see PS1.


PS1. The code, which is used for painting. OCanvas - TCanvas metafile.

  iHPage : integer; // high page
  with oCanvas do begin

    iHPage := 3000;

   // fill rect metafile white - for further work
    Pen.Color   := clBlack;
    Brush.Color := clWhite;
    FillRect( Rect( 0, 0, 2000, iHPage ) );

   // set font - consider other scaling
    oCanvas.Font.Assign( oGrid.Font);
    oCanvas.Font.Size := Round( oGrid.Font.Size * kScale );

    xEnd := xBegin;
    iH := round( RowHeights[ iRow ] * kH );
    for iCol := 0 to ColCount - 1 do begin
      x := xEnd;
      xEnd := x + round( ColWidths[ iCol ] * kW );
      Rectangle( x, yBegin, xEnd, yBegin + iH );
      r := Rect( x + 1, yBegin + 1, xEnd - 1, yBegin + iH - 1 );
      s := Cells[ iCol, iRow ];

      DrawText( oCanvas.Handle, PChar( s ), Length( s ), r, DT_WORDBREAK or  DT_CENTER );

Principal, that it is important to remember at this stage is to not overlook, that all deduced plants should use circumscribed coefficients(as you receive them is already your matter). In this case - I of work  with make over TStringGrid, whici have made for mupti-pages seales.

The last item - is necessary organize metafile or bmp to print.

  Info: PBitmapInfo;
  InfoSize: Integer;
  Image: Pointer;
  ImageSize: DWORD;
  Bits: HBITMAP;
  DIBWidth, DIBHeight: Longint;
  PrintWidth, PrintHeight: Longint;

  case ImageType of

    itMetafile: begin
      if Picture.Metafile<>nil then
        Printer.Canvas.StretchDraw( Rect(aLeft, aTop, aLeft+fWidth,
                 aTop+fHeight), Picture.Metafile);

    itBitmap: begin

      if Picture.Bitmap<>nil then begin
        with Printer, Canvas do begin
          Bits := Picture.Bitmap.Handle;
          GetDIBSizes(Bits, InfoSize, ImageSize);
          Info := AllocMem(InfoSize);
            Image := AllocMem(ImageSize);
              GetDIB(Bits, 0, Info^, Image^);
              with Info^.bmiHeader do begin
                DIBWidth := biWidth;
                DIBHeight := biHeight;
              PrintWidth := DIBWidth;
              PrintHeight := DIBHeight;
              StretchDIBits(Canvas.Handle, aLeft, aTop, PrintWidth,
                        PrintHeight, 0, 0, DIBWidth, DIBHeight, Image, Info^,
                        DIB_RGB_COLORS, SRCCOPY);
              FreeMem(Image, ImageSize);
            FreeMem(Info, InfoSize);

In what the idea PreView consists? There is having on hands Metafila, Bmp - painting with recalculate an appearance image (it is necessary to calculate left top an angle and size "preview" image (or representation).
For a featuring image it is enough to use StretchDraw.

After it was possible to deduce plants on a seal, problem of creation PreView resolution as "the home representation".

By the way, when we of work with Bmp, for lock we use the following hint - we note bit image over such of procedure:



Image scaling with minimum distortions, and here of a seal - suit bmp to print just how is circumscribed above.
The result - ours of bmp of a seal hardly is less, than to print her of over WinWord, but it is outwardly - without any distortions and other.

Imho, I for itself of problem of a seal solve. Summare, has made PreView for myStringGrid, where I remove complicated multiline titles and other. On some sheets, there was something up-saw, but with printer at me of problem will not be already precisely :)

PS. By the way, Andrew Aristov because of work has made complicated geomap, which till quality not worse, and can and better, than produces Surfer (experts will understand).


Author Comment

ID: 2595746
An excellent technical answer.
I really appreciated it.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now