Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TCard = class(TGraphicControl)
- private
- // the following message will be performed when the common Text property changes
- procedure CMFontChanged(var AMessage: TMessage); message CM_FONTCHANGED;
- // the following message will be performed when the common Font property changes
- procedure CMTextChanged(var AMessage: TMessage); message CM_TEXTCHANGED;
- protected
- procedure Paint; override;
- published
- // this will add to your control Font and Text properties (like e.g. TEdit has)
- property Font;
- property Text;
- end;
- implementation
- { TCard }
- procedure TCard.CMFontChanged(var AMessage: TMessage);
- begin
- inherited;
- // ask to repaint the control because the Font has changed
- Invalidate;
- end;
- procedure TCard.CMTextChanged(var AMessage: TMessage);
- begin
- inherited;
- // ask to repaint the control because the Text has changed
- Invalidate;
- end;
- procedure TCard.Paint;
- var
- R: TRect;
- S: string;
- begin
- // the S variable is needed here just because the Text parameter of the following TextRect method call
- // needs a declared variable, so let's have one and assign our common Text property value to it
- S := Text;
- // build the rectangle into which you want to render the text
- R := Rect(100, 100, 200, 200);
- // assign the font you want to use to the Canvas.Font before the text drawing; let's use the one from
- // our common Font property
- Canvas.Font := Font;
- // and draw the text
- Canvas.TextRect(R, S, [tfWordBreak]);
- end;
Advertisement
Add Comment
Please, Sign In to add comment