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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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