计算组合框DropDownWidth在C# [英] Calculating ComboBox DropDownWidth in C#

查看:458
本文介绍了计算组合框DropDownWidth在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,一个ComboBox调整大小,使其更小。如何重新计算DropDownWidth属性?我知道如何设置它,但我更喜欢计算适当的宽度,因为它的内容改变。首先,我想到了这些行的东西:

In my application a ComboBox gets resized, so that it is smaller. How do I re-calculate the DropDownWidth property? I know how to set it, but I'd prefer to calculate the proper width because its contents changes. Preferabley, I was thinking of something along these lines:

int iMaxLen = 0;
foreach item in comboBoxList
{
   iMaxLen = (item.Length > iMaxLen) ? item.Length : iMaxLen;
}
comboBoxList.DropDownWidth = iMaxLen;

谢谢。

推荐答案

调整组合框下拉列表宽度到最长字符串宽度
http://www.codeproject.com/KB/combobox/ComboBoxAutoWidth.aspx

这篇关于计算组合框DropDownWidth在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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