Setting Font Size in wxTextCtrl Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Setting Font Size in wxTextCtrl

Post by purplex88 »

I am trying to zoom in wxTextCtrl by changing only font size:

Code: Select all

case '+':
{
	if (event.ControlDown())
	{
		wxTextAttr attr;
		int PointSize = m_textCtrl->GetFont().GetPointSize();
		attr.SetFontPointSize(PointSize + 1);
		m_textCtrl->SetStyle(-1, -1, attr);
	}
	else
		event.Skip();

	break;
}
case '-':
{
	if (event.ControlDown())
	{
		// ....
	}
	else
		event.Skip();

	break;
}
It doesn't work the second time I press Ctrl+. I am looking for the correct way to handle this.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Setting Font Size in wxTextCtrl

Post by doublemax »

Code: Select all

int PointSize = m_textCtrl->GetFont().GetPointSize();
I would guess that this line always returns the same value. Setting an attribute does not change the default font size of the control.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Setting Font Size in wxTextCtrl

Post by purplex88 »

Yes, this is true.I also tried using SetDefaultStyle() but nothing changes.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Setting Font Size in wxTextCtrl

Post by doublemax »

Do one of these:
a) set a bigger font with m_textCtrl->SetFont(...)
b) get the current style with m_textCtrl->GetStyle(...)
c) store the current point size somewhere.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Setting Font Size in wxTextCtrl

Post by purplex88 »

Oh, yes I was about to say that I found the solution.

I used GetFont and SetFont like this:

Code: Select all

wxFont font = m_textCtrl->GetFont();
font.SetPointSize(font.GetPointSize() + 1);
m_textCtrl->SetFont(font);
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Setting Font Size in wxTextCtrl

Post by purplex88 »

However, It appears that Ctrl + key combination is already reserved for something and it doesn't trigger an event I want to handle.

Edit: Never mind, I am now using WXK_NUMPAD_ADD.
Post Reply