Page 1 of 1
Change StringGadget or TextGadget property after creation?
Posted: Tue Mar 24, 2009 9:42 pm
by mesozorn
Is there any way to change the properties of these gadgets, for example, left/right/center alignment of text, after they have already been created?
I have tried various combinations of #ES_RIGHT with SetWindowLong_ and Sendmessage_ but since I know absolutely nothing about Windows API calls and am fumbling in the dark, it's not surprising that I've been unsuccessful.
Posted: Tue Mar 24, 2009 9:54 pm
by srod
It is not possible to change the alignment of a string gadget after it is initially set. Not sure about text gadgets but I would suspect not.
Posted: Tue Mar 24, 2009 9:58 pm
by mesozorn
srod wrote:It is not possible to change the alignment of a string gadget after it is initially set. Not sure about text gadgets but I would suspect not.
Even through the API? Visual Basic manages to allow the TextAlign property to be changed at any time on the fly, so there must be a way that it is accomplishing that..?
Posted: Tue Mar 24, 2009 10:45 pm
by srod
I take it back!
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 250, 20, "Should be right justified!", #ES_CENTER)
ButtonGadget(1, 10, 40, 100, 20, "RIGHT JUSTIFY!")
Repeat
eventID = WaitWindowEvent()
Select eventID
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)&~#ES_CENTER|#ES_RIGHT)
InvalidateRect_(GadgetID(0), 0, 1)
EndSelect
EndSelect
Until eventID = #PB_Event_CloseWindow
EndIf
Posted: Tue Mar 24, 2009 11:02 pm
by Demivec
@srod: your solution doesn't seem to do it for me. XP sp3 32-bit
Posted: Tue Mar 24, 2009 11:07 pm
by srod
Ahhh, then my memory isn't as bad as I figured!!! Just tested on XP and it doesn't work; works on Vista!
I do recall reading some time ago that once an edit control had been created and the alignment set, that it could not be altered. This was before the advent of Vista of course.
Perhaps I am not going nuts after all!

Posted: Wed Mar 25, 2009 2:19 pm
by mesozorn
Well, at least my failed attempts can be chalked up to its not being possible, rather than my just not being able to do it. Thanks guys...
Posted: Wed Mar 25, 2009 2:30 pm
by srod
With my EsGRID control, I create 3 edit controls for use when editing text cells; one for left justification, center and right justifcation. I move the controls off-screen when they are not in use etc. I prefered this option over continually destroying and recreating a single edit control as the text justification changes between cells etc. A pain, and like yourself I was disappointed to find that you could not alter an edit control's text alignment after it had been set etc. (at least on versions of Windows prior to Vista).
It does seem a strange 'omission'.