共用方式為


CComboBox::SetHorizontalExtent

設定的寬度,以像素為單位,下拉式方塊的清單方塊部分可水平捲動。

void SetHorizontalExtent(
   UINT nExtent 
);

參數

  • nExtent
    指定下拉式方塊的清單方塊部分可水平捲動的像素數。

備註

如果清單方塊的寬度小於此值,水平捲軸將會水平捲動清單方塊中的項目。 如果清單方塊的寬度等於或大於這個值,水平捲軸隱藏,或者,如果下拉式方塊具有 CBS_DISABLENOSCROLL 樣式,但是會停用。

範例

// 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);

// Set the horizontal extent so every character of all strings can 
// be scrolled to.
m_pComboBox->SetHorizontalExtent(dx);

需求

Header: afxwin.h

請參閱

參考

CComboBox 類別

階層架構圖

CComboBox::GetHorizontalExtent

CB_SETHORIZONTALEXTENT