组合框宽度取决于最长项目 [英] comboBox width depending on longest item

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

问题描述

我有一个ComboBox,我动态生成并填充一些项目。我想将此控件的宽度设置为最长的项目的宽度。我如何计算一些文本的显示宽度?

i've got a ComboBox that i generate dynamically and fill with some items. i would like to set this control's width to the width of the longest item. how do i count the display width of some text?

编辑:我使用窗体窗体,但我想在asp.net中做它


edit: i'm using windows forms, but i would like to do it in asp.net as well

推荐答案

取决于。您使用的是ASP.NET还是Windows Forms或WPF?您是使用固定宽度还是比例字体?

Depends. Are you using ASP.NET or Windows Forms or WPF? Are you using a fixed-width or proportional font?

如果您使用的是Windows窗体,则需要调用 MeasureString(),以了解您想要的文本宽度。

If you're using Windows Forms, you will want to call MeasureString() in order to find out how wide you want the text to be.

如果您使用ASP.NET,您可以执行类似MeasureString(),但您不知道在浏览器上呈现什么字体,因此你不能把它放在脚本中。

If you're using ASP.NET, you can do something like MeasureString(), but you don't know exactly what font is being rendered on the browser, so you can't just put that in your script.

这篇关于组合框宽度取决于最长项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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