Improve company productivity with a Business Account.Sign Up


Printing Form

Posted on 2000-03-03
Medium Priority
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 20 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…

606 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