如何将文本框动态调整为一定数量字符的宽度? [英] How to dynamically size a textbox to be the width of a certain number of characters?

查看:29
本文介绍了如何将文本框动态调整为一定数量字符的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本框只允许包含一定数量的字符,例如大多数情况下为 12 或 14.

I have some text boxes that are only allowed to contain a certain number of characters, e.g. 12 or 14 in most cases.

是否可以根据单词动态调整文本框的宽度为 12 个字符或 14 个字符的宽度?

Is it possible to dynamically size the text boxes to be the width of 12 characters or 14 characters, depending on the word?

推荐答案

TextRenderer.MeasureText 方法.

只要您不介意使用表单 DLL.

So long as you don't mind using a forms DLL.

或者图形库辅助方法,Graphics.MeasureString.

Or the graphic library helper method, Graphics.MeasureString.

然后您可以使用此信息进行各种大小调整,请查看 MSDN 条目中的示例.

You can then use this info to do all sorts of sizing, check out the examples in the MSDN entries.

这篇关于如何将文本框动态调整为一定数量字符的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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