Changing the Font in a text box 
Author Message
 Changing the Font in a text box

I have created a number of text boxes dynamically but they all seem to
be the same font which i would like to change and also in bold.  I
cant work out how to change this, the code is like

CStatic *m_labels[100];

m_labels[i] = new CStatic()
m_labels[i]->Create("TEXT", WS_VISIBLE, rect, this);

I have tried putting m_labels[i]->SetFont(&font) after this but this
doesnt seem to do anything.

Can anyone help me please?



Fri, 26 Aug 2005 16:53:32 GMT  
 Changing the Font in a text box

Quote:

> I have created a number of text boxes dynamically but they all seem to
> be the same font which i would like to change and also in bold.  I
> cant work out how to change this, the code is like

> CStatic *m_labels[100];

> m_labels[i] = new CStatic()
> m_labels[i]->Create("TEXT", WS_VISIBLE, rect, this);

> I have tried putting m_labels[i]->SetFont(&font) after this but this
> doesnt seem to do anything.

> Can anyone help me please?

Your approach is correct.  Make sure the CFont you use is a member
variable - it has to last as long as the controls.

--
Scott McPhillips [VC++ MVP]



Fri, 26 Aug 2005 20:06:26 GMT  
 Changing the Font in a text box

Quote:


> > I have created a number of text boxes dynamically but they all seem to
> > be the same font which i would like to change and also in bold.  I
> > cant work out how to change this, the code is like

> > CStatic *m_labels[100];

> > m_labels[i] = new CStatic()
> > m_labels[i]->Create("TEXT", WS_VISIBLE, rect, this);

> > I have tried putting m_labels[i]->SetFont(&font) after this but this
> > doesnt seem to do anything.

> > Can anyone help me please?

> Your approach is correct.  Make sure the CFont you use is a member
> variable - it has to last as long as the controls.

Thanks Scott, thats excatly what i was doing wrong.
Another quick question though... how do i center the text horizontally
in the box and how to i change the text colour?  I'm sure it is quite
simple but i cannot see the options in CFont createfont()?


Sun, 28 Aug 2005 02:37:51 GMT  
 Changing the Font in a text box

Quote:
> Another quick question though... how do i center the text horizontally
> in the box

Create the control with SS_CENTER style.

Quote:
> and how to i change the text colour?

Handle WM_CTLCOLORSTATIC message.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sun, 28 Aug 2005 02:42:05 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to change the color,size,font of text in a dialog box

2. Changing font color in static text box

3. How to change the color,size,font of text in a dialog box

4. changing the font for text items in a dialog box

5. Changing Rich Text Box : Text

6. Text with different font in dialog box

7. Using Unicode/Font subsets in text boxes?

8. Text box font/color via DDX

9. Text with different font in dialog box

10. How change font in Text(03h) mode ?

11. How do I change font of a text in dialog

12. Change the font for a text control

 

 
Powered by phpBB® Forum Software