# TextCtrl text alignment

**URL:** <https://www.ruby-forum.com/t/textctrl-text-alignment/170284>\
**Category:** wxRuby\
**Created:** [June 15, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/textctrl-text-alignment/170284 "2009-06-15T14:45:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [June 15, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/textctrl-text-alignment/170284/1 "2009-06-15T14:45:23Z")

</div>

As shown in the attached program, the text "My Long Textbox Value "in  
the TextCtrl object, @my\_textbox, aligns off the screen in Windos XP (32  
bit, SP3)

Any help with this would be appreciated.

Thanks,

Nick G.

---

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [June 15, 2009, 6:43pm UTC](https://www.ruby-forum.com/t/textctrl-text-alignment/170284/2 "2009-06-15T18:43:06Z")

</div>

Hi Nick

Nicholas Gunther wrote:

> As shown in the attached program, the text "My Long Textbox Value "in  
> the TextCtrl object, @my\_textbox, aligns off the screen in Windos XP (32  
> bit, SP3)

I see what you mean - even if only the TextCtrl is present (it always  
helps to reduce your example to as simple as possible to isolate the  
problem).

I think this is just a ‘feature’ of the underlying Windows toolkit - it  
always selects the first widget in a new frame when it’s shown, and when  
selecting a TextCtrl, selects all the text in there. Why it scrolls a  
bit horizontally I don’t know. But you could mitigate this by calling

text\_ctrl.set\_selection\_point(0)  
text\_ctrl.set\_selection\_point\_end

after the call to show()

btw, a couple of things you can write more tersely in wxRuby code:

@my\_label = StaticText.new(@my\_panel, -1, ‘My Label Text’,  
DEFAULT\_POSITION, DEFAULT\_SIZE, ALIGN\_CENTER)

# better as:

@my\_label = StaticText.new(@my\_panel, :label =\> ‘My Label Text’, :style  
=\> ALIGN\_CENTRE)

evt\_button(@my\_button.get\_id()) { |event| my\_button\_click(event)}

# better as:

evt\_button @my\_button, :my\_button\_click

hth  
alex

---

<div class="post-metadata">

**Author:** ![paerez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@paerez](https://www.ruby-forum.com/u/paerez)\
**Post date:** [June 15, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/textctrl-text-alignment/170284/3 "2009-06-15T19:15:49Z")

</div>

Well, that is helpful, although I think perhaps you meant:  
set\_INSERTION\_point(0), not “set\_selection\_point”. 🙂  
BUT point(0), point(1), point(2), point(3), point(4) all produce the  
same good outcome - the text aligned exactly flush with the left margin,  
while “set\_insertion\_point(5)” reproduces the original problem in which  
the text is scrolled to the left and the first characters that appear  
are “ong” from “Long…” I note that the comboBox is text is perfectly  
aligned, exactly one space from the far left margin.  
You did solve the problem, for which I am grateful, but do you know why  
set\_insertion\_point is behaving like this? Is it because in the  
underlying Windows toolkit the earlier insertion points ((i) with i\<5)  
prevent the horizontal scrolling, but a later insertion point permits  
it? I suppose so.  
How odd!  
Thanks again,  
Nick

Alex F. wrote:

> Hi Nick
> 
> Nicholas Gunther wrote:
> 
> > As shown in the attached program, the text "My Long Textbox Value "in  
> > the TextCtrl object, @my\_textbox, aligns off the screen in Windos XP (32  
> > bit, SP3)
> 
> I see what you mean - even if only the TextCtrl is present (it always  
> helps to reduce your example to as simple as possible to isolate the  
> problem).
> 
> I think this is just a ‘feature’ of the underlying Windows toolkit - it  
> always selects the first widget in a new frame when it’s shown, and when  
> selecting a TextCtrl, selects all the text in there. Why it scrolls a  
> bit horizontally I don’t know. But you could mitigate this by calling
> 
> text\_ctrl.set\_selection\_point(0)  
> text\_ctrl.set\_selection\_point\_end
> 
> after the call to show()
> 
> btw, a couple of things you can write more tersely in wxRuby code:
> 
> @my\_label = StaticText.new(@my\_panel, -1, ‘My Label Text’,  
> DEFAULT\_POSITION, DEFAULT\_SIZE, ALIGN\_CENTER)
> 
> # better as:
> 
> @my\_label = StaticText.new(@my\_panel, :label =\> ‘My Label Text’, :style  
> =\> ALIGN\_CENTRE)
> 
> evt\_button(@my\_button.get\_id()) { |event| my\_button\_click(event)}
> 
> # better as:
> 
> evt\_button @my\_button, :my\_button\_click
> 
> hth  
> alex
