Does anyone know if it is possible to have multiple fonts in a text control? I have an app with a multi line text control and a font dialog. When I change the font, it changes the font of everything in the text control. I also tried setting it up as a rich text control and the same thing happens.
I would like to be able to type something, then use the font dialog to change the font for whatever is typed from that point on. Is this possible?
multiple fonts in a text control Topic is solved
-
- Earned some good credits
- Posts: 102
- Joined: Thu Dec 28, 2006 5:12 pm
- Location: Indiana, US
How are you setting the new font in the wxTextCtrl? Are you specifying where to start with the new style?
Code: Select all
myTextCtrl->SetStyle(myTextCtrl->GetInsertionPoint(),myTextCtrl->GetInsertionPoint(),myStyle);
-
- Earned some good credits
- Posts: 102
- Joined: Thu Dec 28, 2006 5:12 pm
- Location: Indiana, US
Well, this is what I was trying that caused everything to be changed.
Based on what you said, I put the following right before the SetFont line.
It didn't work. It still changed all of the text. If I'm doing it wrong, can you show me the right way?
Thank you.
Code: Select all
if(font->ShowModal() == wxID_OK)
{
tcMain->SetFont(font->GetFontData().GetChosenFont());
}
Code: Select all
tcMain->SetStyle(tcMain->GetInsertionPoint(), tcMain->GetInsertionPoint(),
(wxTextAttr) wxTEXT_ATTR_FONT);
Thank you.
Don't do the first part - that sets the font for the whole text control.
Instead, do something like this:
That should set the style for the textctrl from the insertion point forward.
Instead, do something like this:
Code: Select all
if(font->ShowModal() == wxID_OK)
{
wxTextAttr tmp;
tmp.SetFont(font->GetFontData().GetChosenFont());
tcMain->SetStyle(tcMain->GetInsertionPoint(), tcMain->GetInsertionPoint(), tmp);
}
-
- Earned some good credits
- Posts: 102
- Joined: Thu Dec 28, 2006 5:12 pm
- Location: Indiana, US
-
- Earned some good credits
- Posts: 102
- Joined: Thu Dec 28, 2006 5:12 pm
- Location: Indiana, US