Recent

Author Topic: Showing only the rightmost visible characters in a TStaticText?  (Read 11262 times)

wp

  • Hero Member
  • *****
  • Posts: 12849
Re: Showing only the rightmost visible characters in a TStaticText?
« Reply #15 on: September 27, 2013, 02:50:58 pm »
Since you are displaying file names: Did you read Taazz's posting on the function MinimizeName a few postings above? This is the most practical and user-friendly way for displaying too-long file names in a control:

Code: [Select]
  StaticText1.Caption := MinimizeName(Application.ExeName, Canvas, StaticText1.Width);

Notes:
  • The only critical parameter is the Canvas used in the MinimizeName function since TStaticText does not have this property. But a StaticText usually has them same font as its owner, and you can "borrow" the Canvas from it. Therefore, if you are calling above code from the event handler of a form it will work directly (i.e. "Canvas" refers to TForm.Canvas).
  • If fonts are different you have to create a TControlCanvas, and assign the statictext to its Control property.
  • Alternatively, use a TLabel instead of the TStaticText.

CM630

  • Hero Member
  • *****
  • Posts: 1395
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Showing only the rightmost visible characters in a TStaticText?
« Reply #16 on: September 27, 2013, 03:23:40 pm »
Quote
MinimizeName- Returns a shortened version of a file name, so that it fits on the given MaxWidth
If I do use it, I will have to store the filename in a var, that'is why I did it with a panel.
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 12849
Re: Showing only the rightmost visible characters in a TStaticText?
« Reply #17 on: September 27, 2013, 05:06:30 pm »
Very confusing answer: you were talking about TStaticText all the time, now it's a panel... And if the file name is a const you can pass it to MinimizeName anyway - so what is the problem?

CM630

  • Hero Member
  • *****
  • Posts: 1395
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Showing only the rightmost visible characters in a TStaticText?
« Reply #18 on: September 29, 2013, 07:57:08 am »
I put the TStaticText in a Panel. I fixed the size of the panel, but I set the size of the TStaticText  to auto. Then I aligned right what I should, so now only the rightmost part of the  TStaticText is visible.
Somehow I don't feel like using an extra var, but on the other hand, maybe I'll use your solution, since now the text is aligned right, even if it is not longer that the TStaticText.


 
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018