Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing font size in ComboBox?

1,544 views
Skip to first unread message

Alberto Villarroel

unread,
Jun 5, 2001, 4:19:13 PM6/5/01
to
I have a ComboBox is created with "Create" and not as a resource. In
that ComboBox I wan't to use a small font. I searched around in MSDN and
found an example of using the SetFont member function. When I use that
code the ComboBox gets vertically smaller, resembling the new "font"
size. But the text in the ComboBox remains still the default size. How
do I change the size of the text items. Code below follows:

combo.Create(WS_VISIBLE|CBS_SIMPLE |CBS_HASSTRINGS |CBS_AUTOHSCROLL
|CBS_DROPDOWN |
0, CRect(0, 0, 100,00),
this,IDC_COMBO);

// Setting the FONT text, found in MSDN
// Set the font
CFont m_font;
LOGFONT lf; // Used to create the CFont.

memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 15; // Request a 20-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font.
combo.SetFont(&m_font, TRUE);


Any help is appreciated

Alberto.V

David Lowndes

unread,
Jun 5, 2001, 4:56:50 PM6/5/01
to
>I have a ComboBox is created with "Create" and not as a resource. In
>that ComboBox I wan't to use a small font. I searched around in MSDN and
>found an example of using the SetFont member function. When I use that
>code the ComboBox gets vertically smaller, resembling the new "font"
>size. But the text in the ComboBox remains still the default size.

>// Setting the FONT text, found in MSDN


>// Set the font
>CFont m_font;

Alberto,

The font needs to exist for as long as the control using it. The
normal solution is to make the CFont variable a member variable of the
class that is the parent of the control you're using it with.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Alberto Villarroel

unread,
Jun 7, 2001, 5:05:55 AM6/7/01
to
Thank you very much, this solved my problem.

Alberto

0 new messages