Freigeben über


CComboBox::SetHorizontalExtent

Gibt die Breite, in Pixel fest, nach der der Listenfeldbereich des Kombinationsfelds horizontalen Bildlauf durchgeführt werden kann.

void SetHorizontalExtent( 
   UINT nExtent  
);

Parameter

  • nExtent
    Gibt die Anzahl der Pixel an, durch die der Listenfeldbereich des Kombinationsfelds horizontalen Bildlauf durchgeführt werden kann.

Hinweise

Wenn die Breite des Listenfelds kleiner als dieser Wert ist, werden die horizontale Bildlaufleiste horizontal Elemente im Listenfeld aus. Wenn die Breite des Listenfelds ist gleich oder größer als diesen Wert, wird die horizontale Bildlaufleiste oder ausgeblendet, wenn das Kombinationsfeld CBS_DISABLENOSCROLL das Format verfügt, deaktiviert.

Beispiel

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

Anforderungen

Header: afxwin.h

Siehe auch

Referenz

CComboBox-Klasse

Hierarchiediagramm

CComboBox::GetHorizontalExtent

CB_SETHORIZONTALEXTENT