[英]Limit text to width of TextBox
I'm using a TextBox
to create an editable title on something that looks like a post-it note. 我正在使用
TextBox
在看起来像便签纸的东西上创建可编辑的标题。 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. 我从
RichEditBox
更改为TextBox
,以查看是否可以解决我的问题,但没有解决,因此,如果有帮助,我愿意改回来。
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. 我的问题是,我不希望用户输入超出
TextBox
设置宽度的字符,因为我希望整个标题都可见。 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. 为可输入的字符数设置一个固定的限制实际上是行不通的,因为例如10个大的M会填满我的
TextBox
的宽度,而其他字符只会填满一半。 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. 因此,我想将文本的宽度与
TextBox
的宽度进行比较,以便可以限制超出该范围的输入。
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. 编辑:我正在使用Segoe UI字体,并且我真的不考虑将字体更改为等宽字符的字体作为解决方案。
将TextBox字体设置为Courier字体,然后所有字符的宽度相等,并且计算max变得很简单。
I am suck in programming world. 我很喜欢编程世界。 im try help you..
我尝试帮助您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.