Painting wxtextCtrl background 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
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Painting wxtextCtrl background

Post by Widgets »

In a multi-line wxTextCtrl window, I would like to be able to paint the background of alternating lines a different color.

I can do this easily enough when I first fill the control, but I do have to allow for adding and deleting of lines. So if I paint the background when I add the text, things get out of step later on.

To avoid repainting the whole works over and over, I thought of doing it in the OnEraseBackground event handler and I have been able to hook into the event handler to intercept this event, but I'm quite clueless as to how to go about implementing my scheme, if it is even possible.

Any hints or pointers would be most welcome.

I have looked at wxScrolledWindow, but I don't see it fitting in as well as the text control - and besides, it would mean a good bit of rewrite ;-)

TIA
widgets
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
Probot
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Jun 24, 2008 6:56 am

Post by Probot »

Hi!
Try the wxListCtrl. There you can change the color of each line (Item):

http://wiki.wxwidgets.org/WxListCtrl#Us ... _Each_Item
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

I think you are looking for

Code: Select all

wxRichTextCtrl
Chris
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Post by Widgets »

Probot wrote:Hi!
Try the wxListCtrl. There you can change the color of each line (Item):

http://wiki.wxwidgets.org/WxListCtrl#Us ... _Each_Item
It's not so much that I can't change or don't know how to change the background color of a line when I add it. I think I need to do it from the erase background event.

Aside from that, I would have to find out the maximum size of text the list control can handle.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
Widgets
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 534
Joined: Thu Jun 01, 2006 4:36 pm
Location: Right here!

Post by Widgets »

[quote="chris_bern"]I think you are looking for

Code: Select all

wxRichTextCtrl
I have looked at that control, but I think it would be overkill and besides, it does not really change my problem.
If I add background colors during the addition of the text, then I'm going to have to modify every line after the one modified whenever any one line is added or deleted - not a good solution.
To avoid that I want to paint the background separately.

Aug 2008
I have, meanwhile, changed the code to use the wxScrolledWindow
code - still working through the resulting changes.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
Post Reply