I have a Windows Forms application in which I display some client data in a shortcut. I set label.AutoEllipsis = true.
If the text is longer than the label, it looks like this:
Some Text Some longe... // label.Text is actually "Some longer Text" // Full text is displayed in a tooltip
what I want.
But now I want to know if the label uses the AutoEllipsis function at run time. How to do it?
Decision
Thanks max. Now I managed to create a control that tries to put all the text on one line. If anyone is interested, here is the code:
Public Class AutosizeLabel Inherits System.Windows.Forms.Label Public Overrides Property Text() As String Get Return MyBase.Text End Get Set(ByVal value As String) MyBase.Text = value ResetFontToDefault() CheckFontsizeToBig() End Set End Property Public Overrides Property Font() As System.Drawing.Font Get Return MyBase.Font End Get Set(ByVal value As System.Drawing.Font) MyBase.Font = value currentFont = value CheckFontsizeToBig() End Set End Property Private currentFont As Font = Me.Font Private Sub CheckFontsizeToBig() If Me.PreferredWidth > Me.Width AndAlso Me.Font.SizeInPoints > 0.25! Then MyBase.Font = New Font(currentFont.FontFamily, Me.Font.SizeInPoints - 0.25!, currentFont.Style, currentFont.Unit) CheckFontsizeToBig() End If End Sub Private Sub ResetFontToDefault() MyBase.Font = currentFont End Sub End Class
Fine tuning may be required (make a step size and a minimum value that can be set using the visible properties of the designer), but at the moment it works very well.
source share