[Gambas-user] Label control

Bruce Steers bsteers4 at gmail.com
Wed Jun 15 05:01:05 CEST 2022


On Tue, 14 Jun 2022 at 23:27, Steve via User <user at lists.gambas-basic.org>
wrote:

> I am attempting to populate a label control. The text on the control will
> vary. The size of the control does not. Is there a way to detect when the
> text Will overflow the control so that I can split the text up properly to
> display? This would be in the case where there is sufficient vertical room
> but not horizontal. Also the font size will vary
>

Forget the code in that last post, Paint.TrimText() does a lot more than
those few lines i typed from memory at work (must have been a different
function).


Try this function, it can return the trimmed text using Paint.TrimText
and/or update the label...

Public Sub TrimLabelText(hLabel As Label, Optional UpdadeLabel As Boolean)
As String

  Dim sText As String

  Dim i As New Image(5, 5) ' make a dummy image to use Paint.class on
  Paint.Begin(i)
  Paint.Font = hLabel.Font
  sText = Paint.TrimText(hLabel.Text, hLabel.Width, hLabel.Height)
  Paint.End
  i = Null
  If UpdadeLabel And If sText <> hLabel.Text Then hLabel.Text = sText
  Return sText

End

BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220615/ecb3b204/attachment.htm>


More information about the User mailing list