Delphi: TLabel sets the EllipsisPosition property with... When displaying too long text, display its full text with Hint

Still encounter problems in dealing with multiple languages.

Since Delphi version 2006, TLabel has the EllipsisPosition property. When the long text exceeds its size, it will be displayed with ..., as shown below:

Although this solves the display problem, obviously, I don't know...what is omitted.

 

Yu Zhong thought: In this case, can you move the mouse over and display the full text with Hint?

Tracking its source code and consulting the information, I realized this idea and expanded TLabel. The code is as follows:

statement:

type
  TLabel = class(StdCtrls.TLabel)
  protected
    procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
  end;

accomplish:

{ TLabel }

procedure TLabel.DoDrawText(var Rect: TRect; Flags: Integer);
begin
  inherited;

  if (EllipsisPosition <> epNone) and not AutoSize and Assigned(Parent)
    and (not ShowHint or (Hint = ''))
    and (Canvas.TextWidth(Caption) > Width) then
  begin
    ShowHint := True;
    Hint := Caption;
  end;
end;

Put this code in the unit where it is located, or encapsulate it as a separate unit, and refer to it after StdCtrls.

Verify that the problem is resolved. But I can't take a picture, and those who are interested can try it for themselves.

 

References:

How to create resize event for TLabel (TGraphicControl)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325174355&siteId=291194637