c# - How to know if text is bigger than textbox? -


is there way know if text within wpf textbox has exceeded length of it?

** note: i'm talking pixel length not character length of maxlength

so basically, if textbox 50 pixels long. , have text in is: "supercalifragilisticexpialidocious! though sound of quite atrosicous"

then won't fit in there right? i'd know didn't fit in it. if textbox 900 pixels wide. might.

i'm checking following.

    private double getwidthoftext()     {         formattedtext formattedtext = new formattedtext(mytextbox.text,                                             system.globalization.cultureinfo.getcultureinfo("en-us"),                                             flowdirection.lefttoright, new typeface(new fontfamily("arial"), fontstyles.normal, fontweights.bold, fontstretches.normal), mytextbox.fontsize, brushes.black);         return formattedtext.width;     } 

...

 if (textbox.width < getwidthoftext()) ... 

but find incredibly hacky , never works. i'm trying find more reliable. ideas?

if (textbox.extentwidth > textbox.actualwidth) {     // textbox overflowed } 

works .net 4.5.2


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -