调整文本框宽度的大小 [英] Resizing the Textbox width

查看:86
本文介绍了调整文本框宽度的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求根据文本框的最大长度调整文本框宽度。即我正在使用特定的Maxlength值动态添加文本框控件。例如,如果最大长度为4,那么文本框的宽度应该是
,它只能容纳4个字符。

I have a requirement of Resizing the Textbox width based on the maxlength of the textbox. i.e. I am adding textbox control dynamically with specific Maxlength value. For example, if the max length is 4 then the width of the textbox should be such that it can accommodate only 4 characters.

请提示,如何实现这一目标silverlight。

Please suggest, how this can be achieved with silverlight.

谢谢你,

Raj

 

推荐答案

最简单的方法是手动确定前面使用的字体系列和大小的单个字符的近似宽度,只需设置Width属性即可到MaxLenght *这个静态/恒定宽度。

The easiest way to do this is probably to manually determine the approximate width of a single character for the font family and size you are using up front and simply set the Width property to MaxLenght * this static/constant width.

或者你可以看看以下方法:

Alternatively you could take a look at the following approach:

如何限制MaxLength TextBox?:
http://stackoverflow.com / questions / 4334792 / wpf-how-to-restrict-maxlength-of-textbox

希望有所帮助。

请记住通过将有用的帖子标记为答案来关闭您的主题d如果你有新问题,那么就开始一个新的主题。请不要在同一个帖子中提出几个问题。

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于调整文本框宽度的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆