📄 drawtextu.pas
字号:
unit drawtextU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormPaint(Sender: TObject);
var
BoundingRect: TRect; // the text formatting rectangle
CurDirectory: array[0..MAX_PATH] of char; // the directory string
begin
{create the text formatting bounding rectangle}
BoundingRect := Rect(Label1.Left, Label1.Top+Label1.Height+3,
Form1.Width-(Label1.Left*2), Label1.Top+Label1.Height+83);
{draw this rectangle visually on the form}
Form1.Canvas.Rectangle(BoundingRect.Left, BoundingRect.Top,
BoundingRect.Right, BoundingRect.Bottom);
{set the form's background mode for transparency}
SetBkMode(Form1.Canvas.Handle, TRANSPARENT);
{draw text at the bottom left of the rectangle}
DrawText(Form1.Canvas.Handle, 'Delphi Rocks!', -1, BoundingRect,
DT_BOTTOM or DT_SINGLELINE);
{draw text in the very center of the rectangle}
DrawText(Form1.Canvas.Handle, 'Delphi Rocks!', -1, BoundingRect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE);
{draw text at the top right of the rectangle}
DrawText(Form1.Canvas.Handle, 'Delphi Rocks!', -1, BoundingRect,
DT_TOP or DT_RIGHT);
{create a new text formatting bounding rectangle}
BoundingRect := Rect(Label2.Left, Label2.Top+Label2.Height+3,
Label2.Width+Label2.Left, Label2.Top+Label2.Height+73);
{draw the rectangle visually}
Form1.Canvas.Rectangle(BoundingRect.Left, BoundingRect.Top,
BoundingRect.Right, BoundingRect.Bottom);
{draw word wrapped text within the rectangle}
DrawText(Form1.Canvas.Handle, 'Delphi is the most awesome Windows '+
'development environment on the market.', -1, BoundingRect,
DT_WORDBREAK);
{create a new text formatting bounding rectangle}
BoundingRect := Rect(Label3.Left, Label3.Top+Label3.Height+3,
Label3.Width+Label3.Left, Label3.Top+Label3.Height+25);
{retrieve the current directory}
GetCurrentDirectory(MAX_PATH, CurDirectory);
{draw the directory string within the rectangle, reducing it as necessary}
DrawText(Form1.Canvas.Handle, CurDirectory, -1, BoundingRect,
DT_PATH_ELLIPSIS);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -