Reputation: 13
I'm using a TextBox
to create an editable title on something that looks like a post-it note. I changed to a TextBox
from a RichEditBox
to see if that could solve my problem, which it didn't, so I'm willing to change back if that helps.
My problem is that I don't want the user to be able to enter more characters than fit in the set width of the TextBox
, because I want the whole title to be visible. Setting a fixed limit to the amount of characters that can be entered doesn't really work since for example 10 large M's would fill the width of my TextBox
, but other characters will only fill half of it. So I would like to compare the width of the text to the width of the TextBox
, so I can restrict input beyond that point.
Edit: I'm using the Segoe UI font, and I don't really consider changing the font to one with characters of equal width as a solution.
Upvotes: 0
Views: 1152
Reputation: 631
Set the TextBox Font to a Courier Font, then all characters are equal width and calculating max becomes trivial.
Upvotes: 0