Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

change button font

Posted on 2001-08-24
4
Medium Priority
?
1,132 Views
Last Modified: 2013-12-03
i have created a button dynamically in MFC. i would like to set MFC default font for this button.

How can i do this?
0
Comment
Question by:pratimag
[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
4 Comments
 
LVL 4

Expert Comment

by:albay
ID: 6423802
hi pratimag. try this...

CFont font;
     font.CreatePointFont(120,_T("Times New Roman"));
     CButton* button = (CButton*) GetDlgItem(IDC_BUTTON2);
     //IDC_BUTTON2 = your button ID
     CDC* dc = button->GetDC();
     CFont* pOldFont = dc->SelectObject(&font);
     CString str; button->GetWindowText(str);
     if(!str.IsEmpty()) {
          CRect rect; button->GetClientRect(&rect);
          button->SetWindowText(_T(""));
          dc->SetBkMode(TRANSPARENT);
          dc->DrawText(str,&rect,DT_CENTER);
     }
     dc->SelectObject(pOldFont);
     button->ReleaseDC(dc);

hope this helps,
best wishes.
albay
0
 
LVL 9

Expert Comment

by:Pacman
ID: 6427674
> i would like to set MFC default font for this button.

what do you mean with "default font".
The button has already a default font after creation.
0
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 40 total points
ID: 6429223
If you want to change the font that the button uses when it draws itself, create a CFont object similar to how "albay" does, but use CWnd::SetFont(...) to set the font for the button itself.

For example:

//
//  Assume You Have "m_btButton" Bound To The Button Control
//  By Using ClassWizard And Have A CFont Object ("m_fMyFont")
//Created And Initialized Already...
//
m_btButton.SetFont( &m_fMyFont );

That will cause the button to use the new font whenever it draws its text (BTW: this works for other controls, like the Edit, Static, and ListView as well).

IMHO, Drawing the button text, when the button can already do that itself is using a shotgun to kill a fly.

-=- James.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9528428
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: jtwine

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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

618 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