为了摆脱对表单大小调整的依赖,如果您使用拆分器,也可能会发生调整大小,您可以覆盖 CanResize 事件以调整您的标题。
例如:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TLabel = Class(StdCtrls.TLabel)
private
FFullCaption: String;
procedure SetFullname(const Value: String);
published
function CanResize(var NewWidth, NewHeight: Integer): Boolean; override;
property FullCaption: String read FFullCaption Write SetFullname;
End;
TForm3 = class(TForm)
FileNameLabel: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
uses FileCtrl;
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
FileNameLabel.FullCaption := 'C:\ADirectory\ASubDirectory\ASubSubDirectory\AFileN.ame'
end;
{ TLabel }
function TLabel.CanResize(var NewWidth, NewHeight: Integer): Boolean;
begin
inherited;
if Assigned(Parent) then
Caption := MinimizeName(FFullCaption, Canvas, NewWidth)
end;
procedure TLabel.SetFullname(const Value: String);
begin
FFullCaption := Value;
Caption := MinimizeName(FFullCaption, Canvas, Width)
end;
end.