TLama

Untitled

Oct 19th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.50 KB | None | 0 0
  1. type
  2.   TCard = class(TGraphicControl)
  3.   private
  4.     // the following message will be performed when the common Text property changes
  5.     procedure CMFontChanged(var AMessage: TMessage); message CM_FONTCHANGED;
  6.     // the following message will be performed when the common Font property changes
  7.     procedure CMTextChanged(var AMessage: TMessage); message CM_TEXTCHANGED;
  8.   protected
  9.     procedure Paint; override;
  10.   published
  11.     // this will add to your control Font and Text properties (like e.g. TEdit has)
  12.     property Font;
  13.     property Text;
  14.   end;
  15.  
  16. implementation
  17.  
  18. { TCard }
  19.  
  20. procedure TCard.CMFontChanged(var AMessage: TMessage);
  21. begin
  22.   inherited;
  23.   // ask to repaint the control because the Font has changed
  24.   Invalidate;
  25. end;
  26.  
  27. procedure TCard.CMTextChanged(var AMessage: TMessage);
  28. begin
  29.   inherited;
  30.   // ask to repaint the control because the Text has changed
  31.   Invalidate;
  32. end;
  33.  
  34. procedure TCard.Paint;
  35. var
  36.   R: TRect;
  37.   S: string;
  38. begin
  39.   // the S variable is needed here just because the Text parameter of the following TextRect method call
  40.   // needs a declared variable, so let's have one and assign our common Text property value to it
  41.   S := Text;
  42.   // build the rectangle into which you want to render the text
  43.   R := Rect(100, 100, 200, 200);
  44.   // assign the font you want to use to the Canvas.Font before the text drawing; let's use the one from
  45.   // our common Font property
  46.   Canvas.Font := Font;
  47.   // and draw the text
  48.   Canvas.TextRect(R, S, [tfWordBreak]);
  49. end;
Advertisement
Add Comment
Please, Sign In to add comment