# wxRichTextCtrl not Working through wxFormBuilder

**URL:** <https://www.ruby-forum.com/t/wxrichtextctrl-not-working-through-wxformbuilder/193146>\
**Category:** wxRuby\
**Created:** [August 12, 2010, 3:46am UTC](https://www.ruby-forum.com/t/wxrichtextctrl-not-working-through-wxformbuilder/193146 "2010-08-12T03:46:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [August 12, 2010, 3:46am UTC](https://www.ruby-forum.com/t/wxrichtextctrl-not-working-through-wxformbuilder/193146/1 "2010-08-12T03:46:11Z")

</div>

I’ve used wxFormBuilder to put a wxRichTextCtrl on my form. After doing  
this, I run xrcise and try to use the control. The variable for the rich  
text control is a FixNum. On examination, I saw that the class name in  
the xrc file is “unknown”.

Is there no way to use this control without manually laying out the  
controls - or writing this routine in C++? Does anyone know a  
workaround?

Thanks in advance.  
—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [August 12, 2010, 9:20am UTC](https://www.ruby-forum.com/t/wxrichtextctrl-not-working-through-wxformbuilder/193146/2 "2010-08-12T09:20:05Z")

</div>

Hi

On 12/08/2010 02:46, Michael S. wrote:

> I’ve used wxFormBuilder to put a wxRichTextCtrl on my form. After doing  
> this, I run xrcise and try to use the control. The variable for the rich  
> text control is a FixNum. On examination, I saw that the class name in  
> the xrc file is “unknown”.
> 
> Is there no way to use this control without manually laying out the  
> controls - or writing this routine in C++? Does anyone know a  
> workaround?

I worked around it by designing the XRC with a bog-standard  
Wx::TextCtrl, then in the initialise method of the inheriting Ruby  
class, replacing it with a RichTextCtrl.

I wrote a convenience method to handle it properly. It’s called like  
this (assuming a TextCtrl mapped to the instance var @text\_box)

rtc = Wx::RichTextCtrl.new(…)  
replace\_xrc(:text\_box, rtc)

The replace\_xrc method looks like this:

class Wx::Window

# Convenience function to replace one Window with another. Useful

# because there are elements which are not available or convenient in

# XRC, but a placeholder can be used with a real child created in

# ruby.

# 

# Expects a symbol (eg :@child by which the old can be got) and a new

# child to replace it. The instance variable’s value is overwritten.

def replace\_xrc(old\_sym, new\_win)  
old\_win = instance\_variable\_get(“@#{old\_sym}”)  
old\_win.containing\_sizer.replace( old\_win, new\_win )  
old\_win.destroy  
instance\_variable\_set(“@#{old\_sym}”, new\_win)  
new\_win.containing\_sizer.layout  
end  
end

(from  
[http://weft-qda.rubyforge.org/svn/trunk/weft-qda/lib/weft/wxgui/utilities.rb](http://weft-qda.rubyforge.org/svn/trunk/weft-qda/lib/weft/wxgui/utilities.rb))

hth  
alex

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [September 23, 2010, 3:43pm UTC](https://www.ruby-forum.com/t/wxrichtextctrl-not-working-through-wxformbuilder/193146/3 "2010-09-23T15:43:38Z")

</div>

> I wrote a convenience method to handle it properly. It’s called like  
> this (assuming a TextCtrl mapped to the instance var @text\_box)

thanks, that worked fine for me, too.

One thing to note is that, strangely, it doesn’t work if the RTC is the  
only control in the sizer. So make sure that there is at least one more  
control in the same sizer with your edit control.

Cheers,  
Tony
