CComboBox::SetDroppedWidth

허용 가능한 최소 너비를 콤보 상자의 목록 상자에 픽셀 단위로 설정 하려면이 함수를 호출 합니다.

int SetDroppedWidth( 
   UINT nWidth  
);

매개 변수

  • nWidth
    최소 허용 가능한 너비 픽셀에서 콤보 상자의 목록 상자 부분입니다.

반환 값

성공적으로 새 목록 너비, 그렇지 않으면 상자 CB_ERR.

설명

이 함수를 콤보 상자에만 적용 된 CBS_DROPDOWN 또는 CBS_DROPDOWNLIST 스타일입니다.

기본적으로 최소 허용 드롭 다운 목록 상자 너비는 0입니다. 콤보 상자의 목록 상자 부분에 표시 되 면 너비가 큰 허용 가능한 최소 너비를 콤보 상자 너비입니다.

예제

// Find the longest string in the combo box.
CString    str;
CSize      sz;
int        dx = 0;
TEXTMETRIC tm;
CDC*       pDC = m_pComboBox->GetDC();
CFont*     pFont = m_pComboBox->GetFont();

// Select the listbox font, save the old font
CFont* pOldFont = pDC->SelectObject(pFont);
// Get the text metrics for avg char width
pDC->GetTextMetrics(&tm);

for (int i = 0; i < m_pComboBox->GetCount(); i++)
{
   m_pComboBox->GetLBText(i, str);
   sz = pDC->GetTextExtent(str);

   // Add the avg width to prevent clipping
   sz.cx += tm.tmAveCharWidth;

   if (sz.cx > dx)
      dx = sz.cx;
}
// Select the old font back into the DC
pDC->SelectObject(pOldFont);
m_pComboBox->ReleaseDC(pDC);

// Adjust the width for the vertical scroll bar and the left and right border.
dx += ::GetSystemMetrics(SM_CXVSCROLL) + 2*::GetSystemMetrics(SM_CXEDGE);

// Set the width of the list box so that every item is completely visible.
m_pComboBox->SetDroppedWidth(dx);

요구 사항

헤더: afxwin.h

참고 항목

참조

CComboBox 클래스

계층 구조 차트

CComboBox::GetDroppedWidth

CB_SETDROPPEDWIDTH