Board index » delphi » TMemo.PaintTo when TMemo is not visible

TMemo.PaintTo when TMemo is not visible

Is there a way to paint the contents of a TMemo into a bitmap when the TMemo
component is not visible?  I can do this fine provided TMemo.visible = true.
However I would like to keep this TMemo hidden yet would  still like to get
access
to its formated output (i.e., what would be showing on the screen if it were
visible).
 

Re:TMemo.PaintTo when TMemo is not visible


TJO -

Sorry, but "No". All you can do is copy the TMemo's Canvas (and then
only the portion that is visible) to a bitmap.

But you can cheat here. You can ask the TMemo for each line it would
display if it were visible, and then draw that directly onto your
bitmap. Repeat until all lines are drawn. Don't forget to pick up the
font.

Good luck.

Kurt

Re:TMemo.PaintTo when TMemo is not visible


Quote
> Is there a way to paint the contents of a TMemo into a bitmap when the TMemo
> component is not visible?  I can do this fine provided TMemo.visible = true.
> However I would like to keep this TMemo hidden yet would  still like to get
> access
> to its formated output (i.e., what would be showing on the screen if it were
> visible).

It requires a bit of coding but is possible:

procedure TForm1.Button1Click(Sender: TObject);
var
  r: TRect;
  firstchar: Integer;
  S: String;
begin
  with image1.Picture.bitmap do begin
    width := memo1.clientwidth;
    height := memo1.clientheight;
  end;
  with image1.Picture.bitmap.canvas do begin
    brush.color := memo1.color;
    brush.style := bsSolid;
    fillrect( cliprect );
    font := memo1.font;
    memo1.perform( em_getrect, 0, lparam(@r));
    firstchar := memo1.perform( EM_LINEINDEX,
                                memo1.perform(em_getfirstvisibleline,0,0),
                                0 );
    S:= Copy( memo1.text, firstchar+1, maxint );
    TextOut(r.left, r.top,' '); // ensures font is selected
    DrawTextEx( handle, @S[1], Length(S), r,
                DT_WORDBREAK or DT_LEFT or DT_EDITCONTROL, nil );
  end;

end;

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads