控件TComboBox 下拉列表中 选项长度太长 怎么在选择的时候能看到完整(控件对象长度有限)

控件TComboBox 下拉列表中 选项长度太长 如何在选择的时候能看到完整(控件对象长度有限)
谢谢

------解决方案--------------------
定义一int ComMaxLen;
先计算出ComboBox1中最长的ComMaxLen

(这个自己算一下,如果你的内容是固定的,也可以设ComMaxLen为一固定值,如300)

void __fastcall TForm1::ComboBox1DropDown(TObject *Sender)
{
ComboBox1->Perform(CB_SETDROPPEDWIDTH, ComMaxLen, 0);
}
------解决方案--------------------
以前写的一个例子:
C/C++ code
void __fastcall SetComboDropDownWidth(TComboBox *cbx, long lWidth)
{
    if (lWidth < cbx->Width)
    {
        cbx->Canvas->Handle = GetDC(cbx->Handle);
        try
        {
            for (int i=0; i<cbx->Items->Count; i++)
            {
                int nTextLen = cbx->Canvas->TextWidth(cbx->Items->Strings[i]);
                if (nTextLen > lWidth)
                    lWidth = nTextLen;
            }
            lWidth += 10;
        }
        // Standard ComboBox drawing is Rect.Left + 2, adding the extra spacing offsets this
        __finally
        {
            ReleaseDC(cbx->Handle, cbx->Canvas->Handle);
        }
        SendMessage(cbx->Handle, CB_SETDROPPEDWIDTH, lWidth, 0);
    }
}