Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Changing the font size in tree and list controls

Hi,

I need to programatically increase the font size of a tree/list control.  I've tried using the CFont and LOGFONT objects but I get weird results.

I also need to reset the font size to its original state.

Here's what I tried for increasing the size:
{
 CFont new_font;
CFont* old_font;
LOGFONT lf;

//get the tree control's current font object
old_font = m_wndTree.GetFont();
old_font->GetLogFont(&lf);

//increase the size
lf.lfHeight+= 4;
lf.lfWidth += 2;

//create a new font with this adjusted information
new_font.CreateFontIndirect(&lf);
m_wndTree.SetFont(&new_font);
}

It kind of works, but just once, and the text gets cut off.  Then when I try again during the same execution, the text disappears.

Then to reset the size, I do something similar:
{
CFont new_font;

//mDefaultFont is of type LOGFONT and is set when the dialog is initialized using (essentially) tree->getFont()->getLogFont();
new_font.CreateFontIndirect(&mDefaultFont);
m_wndTree.SetFont(&new_font);
}

Thanks
Marisa
0
marisademeglio
Asked:
marisademeglio
  • 2
  • 2
1 Solution
 
AndyAinscowCommented:
The CFont needs to be a member variable of the class.  What you are doing is creating the font, setting the font for the tree/list then destroying the font leaving the tree/list with an invalid font for drawing.
0
 
Amritpal SinghCommented:
have a look at the following link

http://www.codersource.net/mfc_clistbox_font.html
0
 
Amritpal SinghCommented:
0
 
marisademeglioAuthor Commented:
Thanks!
Adding the font object as a class member worked.  I also had to keep a int variable in the class to represent the current point size; not sure why it wasn't being retrieved correctly from the tree on each iteration.  Anyway, it works now.  
marisa
0
 
AndyAinscowCommented:
Please accept the answer to close the question.  It isn't done automatically.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now