Change StringGadget or TextGadget property after creation?

Just starting out? Need help? Post your questions and find answers here.
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Change StringGadget or TextGadget property after creation?

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Post 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..?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I take it back! :oops:

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
I may look like a mule, but I'm not a complete ass.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

@srod: your solution doesn't seem to do it for me. XP sp3 32-bit
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
mesozorn
Enthusiast
Enthusiast
Posts: 171
Joined: Fri Feb 20, 2009 2:23 am

Post 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...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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'.
I may look like a mule, but I'm not a complete ass.
Post Reply