Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting Font in CEdit

Posted on 1998-09-11
4
Medium Priority
?
835 Views
Last Modified: 2013-12-03
Hi,

I am having trouble setting the font for a CEdit.
void someroutine( );
{
  CFont fnt;
  fnt.CreatePointFont( 100, "Times New Roman" );
  setfont( &fnt );
}

void setfont( CFont* fnt )
{
  m_Edit.SetFont( &fnt )
}

The trouble is that the control does not seem to redraw correctly.

I have tried m_Edit.InvalidateRect( NULL ), which also does not help.

I have changed the m_Edit to an m_pEdit (CEdit*) and re-created the edit control then set the font, and this also doesn't work, which I find *very* odd.

The font does change, but if you make it bigger than the current font, the cursor size is small and the individual lines in the CEdit are drawn very squashed, covering each other. The cursor also looks to narrow for the height of the text?

Please note that I am using a property sheet.
Each property sheet has an edit control on it, and some must be proportional fonts, and others not.

I don't get it.


Regards
-craig.
0
Comment
Question by:cmain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Accepted Solution

by:
bobbym earned 200 total points
ID: 1322076
For me the problem seem to be that the CFont object is destroyed and so the associated Windows object is destroyed too. To correct it just call font.Detach() before you exit someroutine and everything will be OK.

Hope that helped :)
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1322077
I agree with BobbyM,

You could also add the font pointer to your header file and create the fonts during the constructor of the property sheet.  Then within the OnSetActive of each page, then call

m_Edit.SetFont( m_fntProportional );

Then you only have to create the fonts once and use them whenever you need to.

Make sure you delete them in the destructor!  

Phillip

0
 
LVL 1

Author Comment

by:cmain
ID: 1322078
Your answer was right on the button (no pun intended).
Do you know if there are docs on when to use the detach methods?
Thankx

0
 

Expert Comment

by:bobbym
ID: 1322079
Hmmm whenerver you need it :)). Well genereally whenever you need to disconnect the relationship between the C++ object and the Windows object that's it. Sorry I do not know about any docs.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question