DevAdmin Blog

Blog di Ermanno Goletto (Microsoft MVP Directory Services - MCITP - MCTS - MCSA - MCP)
posts - 886, comments - 447, trackbacks - 13

My Links

News

Avatar

Curriculum Vitae

Visualizza il profilo di Ermanno Goletto su LinkedIn


Il contenuto di questo blog e di ciascun post viene fornito “così come é”, senza garanzie, e non conferisce alcun diritto. Questo blog riporta il mio personale pensiero che non riflette necessariamente il pensiero del mio datore di lavoro.

Logo Creative Commons Deed


Logo SysAdmin.it SysAdmin.it Staff


Logo TechNet Forum TechNet Italia @ForumTechNetIt Follow TechNet Forum on Twitter


Logo MVP


Ermanno Goletto Follow ermannog on Twitter

Article Categories

Archives

Post Categories

Blogs

Friends

Knowledge Base

MVP Sites

Resources

Come verificare se un testo può essere visualizzato in un area prefissata

 

Questa funzione permette di verificare se un testo è visualizzabile integralmente in un area prefissata e può essere utile nei casi in cui si voglia visualizzare un ToolTip per testi che superano lo spazio messo a disposizione da un controllo (xes. un tooltip sugli item di un ListView in modalità dettaglio il cui testo supera la larghezza della colonna)

Public Function IsTextExceedSize(ByVal graphics As System.Drawing.Graphics, _
                                                     ByVal text As String, _
                                                     ByVal font As System.Drawing.Font, 
                                                     ByVal width As Integer, _
                                                     ByVal height As Integer) As Boolean

   Dim textSize As System.Drawing.SizeF
   Dim charactersFitted, linesFitted As Integer
   Dim layoutRect As New System.Drawing.SizeF(width, height)

   textSize = graphics.MeasureString(text, font, layoutRect, _
                        System.Drawing.StringFormat.GenericTypographic, _
                        charactersFitted, linesFitted)

   layoutRect = Nothing

   If textSize.Width > width Then Return True

   If textSize.Height > height Then Return True

  Return text.Length > charactersFitted
End Function

Print | posted on Monday, February 23, 2004 5:33 PM | Filed Under [ Code, Snippets & Scripts .NET ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 7 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET