Page 1 of 1

Center one or multiline text in TextGadget [Resolved]

Posted: Wed Oct 01, 2014 5:02 pm
by Kwai chang caine
Hello at all

I try to always center a text in a TextGadget, but without succes :|
That's works when they are one line thanks to the #SS_CENTERIMAGE but if i use this constant, the multiline not works :cry:

Code: Select all

Enumeration
 #Form0
 #Label0
 #Bouton0
EndEnumeration

OpenWindow(#Form0, 642, 252, 394, 100, "New window ( 0 )",  #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar )
TextGadget(#Label0, 20, 2, 357, 48, "Short text", #PB_Text_Center|#PB_Text_Border|#SS_CENTERIMAGE)
ButtonGadget(#Bouton0, 82, 70, 235, 26, "ChangeText")

Repeat

 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
 
 Select Evenement
  
  Case #PB_Event_Gadget
   
   If EvenementGadget = #Bouton0
    SetGadgetText(#Label0, "I'm a long text, and i want to be in the middle of the TexGadget." + #CRLF$ + "But apparently this donkey of KCC cannot force me to do this")
   EndIf
    
 EndSelect

Until Evenement = #PB_Event_CloseWindow
Have a good day

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:10 pm
by DK_PETER
use #ES_CENTER instead of #SS_CENTERIMAGE

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:14 pm
by bobobo
Hi there

change #SS_CENTERIMAGE to #ES_CENTER

greetz

-- wow .. a little late :mrgreen:

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:18 pm
by ts-soft
DK_PETER wrote:use #ES_CENTER instead of #SS_CENTERIMAGE
#ES_ stand for EditStyle (StringGadget). A TextGadget have no EditStyle, a TextGadget have a StaticStyle (#SS_)!
And your code doesn't work, the Text is not centered in Control :wink:

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:20 pm
by Kwai chang caine
Thanks at you two for your flash quick answers 8) :D

Unfortunately i use #ES_CENTER like you say together , but the text is not center vertically with one or several lines :cry:

Edit : Exactely like TsSoft say :wink:

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:21 pm
by Kwai chang caine
Perhaps it's possible to change the parameters dynamically, with a thing like SendMessage_() ??
One when i have one line, and another when i have several

Code: Select all

Enumeration
 #Form0
 #Label0
 #Bouton0
EndEnumeration

OpenWindow(#Form0, 642, 252, 394, 100, "New window ( 0 )", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar)
TextGadget(#Label0, 20, 2, 357, 48, "Short text", #PB_Text_Center|#PB_Text_Border|#SS_CENTERIMAGE)
ButtonGadget(#Bouton0, 82, 70, 235, 26, "ChangeText")

Repeat

 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
 
 Select Evenement
  
  Case #PB_Event_Gadget
   
   If EvenementGadget = #Bouton0
    SendMessage_(#Label0, #????)
    SetGadgetText(#Label0, "I'm a long text, and i want to be in the middle of the TexGadget." + #CRLF$ + "But apparently this donkey of KCC cannot force me to do this")
   EndIf
    
 EndSelect

Until Evenement = #PB_Event_CloseWindow

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:23 pm
by ts-soft
You can remove the flag (#ES_CENTER) with the same result!

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:25 pm
by Kwai chang caine
Justely...how i can modify a parameter dynamically ???

Code: Select all

SendMessage_(#Label0, #????)

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 5:46 pm
by RASHAD
Hi KCC
Center Hal & Val

Code: Select all

Enumeration
 #Form0
 #Cont0
 #Label0
 #Bouton0
EndEnumeration

OpenWindow(#Form0, 642, 252, 394, 100, "New window ( 0 )",  #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar )
ContainerGadget(#Cont0,20,2,357,48,#PB_Container_Flat)
SetGadgetColor(#Cont0,#PB_Gadget_BackColor,$CFFEFE)
      StartDrawing(WindowOutput(#Form0))
         height = TextHeight("W")
      StopDrawing()
      th = (48-Height)/2
      TextGadget(#Label0, 0,th, 357, 48, "Short text", #PB_Text_Center)
      SetGadgetColor(#Label0,#PB_Gadget_BackColor,$CFFEFE)
      SetGadgetColor(#Label0,#PB_Gadget_FrontColor,$2A2FFE)
CloseGadgetList()

ButtonGadget(#Bouton0, 82, 70, 235, 26, "ChangeText")

Repeat

 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
 
 Select Evenement
 
  Case #PB_Event_Gadget
   
   If EvenementGadget = #Bouton0
    SetGadgetText(#Label0, "I'm a long text, and i want to be in the middle of the TexGadget." + #CRLF$ + "But apparently this donkey of KCC cannot force me to do this")
    th = (48-2*Height)/2
    ResizeGadget(#Label0,0,th,#PB_Ignore,#PB_Ignore)
   EndIf
   
 EndSelect

Until Evenement = #PB_Event_CloseWindow

Re: Center one or multiline text in TextGadget

Posted: Wed Oct 01, 2014 6:00 pm
by Kwai chang caine
Hello RASHAD :D
Thanks a lot for your help 8)

Apparently you are forced to draw yourself the text at the place of Microsoft :mrgreen:
And you are not paid for that :lol:

It's already a good solution, apparently they are not magical solution for the TextBox do that hitself :cry:

Thanks a lot at you all to have helped me also quickly 8)
I wish you a very good day

Ps : Just for do some try, i have not found how sending to a gadget new parameters dynamically, can you help me ?

Re: Center one or multiline text in TextGadget [Resolved]

Posted: Wed Oct 01, 2014 7:21 pm
by chi
this kinda works ;)

Code: Select all

Enumeration
 #Form0
 #Label0
 #Bouton0
EndEnumeration

OpenWindow(#Form0, 642, 252, 394, 100, "New window ( 0 )", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar)
TextGadget(#Label0, 20, 2, 357, 58, "Short text", #PB_Text_Center|#PB_Text_Border|#SS_CENTERIMAGE)
ButtonGadget(#Bouton0, 82, 70, 235, 26, "ChangeText")

Repeat

 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
 
 Select Evenement
 
  Case #PB_Event_Gadget
   
   If EvenementGadget = #Bouton0
    SetWindowLongPtr_(GadgetID(#Label0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Label0), #GWL_STYLE) & ~#SS_CENTERIMAGE)
    SetGadgetText(#Label0, #CRLF$ + "I'm a long text, and i want to be in the middle of the TexGadget." + #CRLF$ + "But apparently this donkey of KCC cannot force me to do this")
   EndIf
   
 EndSelect

Until Evenement = #PB_Event_CloseWindow

Re: Center one or multiline text in TextGadget [Resolved]

Posted: Thu Oct 02, 2014 10:24 am
by Kwai chang caine
Image
YEEEESSSSS !!!!!


It's exactely what i want !!! :D
This is the magical sentence that i search since a long time :wink:

Code: Select all

SetWindowLongPtr_(GadgetID(#Label0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Label0), #GWL_STYLE) & ~#SS_CENTERIMAGE)
Thanks a lot CHI, you win a big french kiss !!! :mrgreen:

Again a time.... thanks to you all, for try or help little KCC !!! 8) 8)

Have a veeeeeryyyyyyyy good week-end all my family !!!!!!

Re: Center one or multiline text in TextGadget

Posted: Thu Oct 02, 2014 10:44 am
by DK_PETER
ts-soft wrote:#ES_ stand for EditStyle (StringGadget). A TextGadget have no EditStyle, a TextGadget have a StaticStyle (#SS_)!
I know..Typoe...Should have been #SS_CENTER.
ts-soft wrote:And your code doesn't work, the Text is not centered in Control :wink:
Though I typed the wrong constant, it still centered the text.
At least it does so using Windows 7 64 bit.
The code below centers the text just fine.
Both #ES_CENTER and SS_CENTER returns the value of 1.

Code: Select all

Enumeration
 #Form0
 #Label0
 #Bouton0
EndEnumeration

OpenWindow(#Form0, 642, 252, 394, 100, "New window ( 0 )", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar)
TextGadget(#Label0, 20, 2, 357, 58, "Short text", #PB_Text_Border|#SS_CENTER)
ButtonGadget(#Bouton0, 82, 70, 235, 26, "ChangeText")

Repeat

 Evenement = WaitWindowEvent()
 EvenementGadget = EventGadget()
 EvenementType = EventType()
 
 Select Evenement
 
  Case #PB_Event_Gadget
   
   If EvenementGadget = #Bouton0
    SetGadgetText(#Label0, #CRLF$ + "I'm a long text, and i want to be in the middle of the TexGadget." + #CRLF$ + "But apparently this donkey of KCC cannot force me to do this")
   EndIf
   
 EndSelect

Until Evenement = #PB_Event_CloseWindow

Re: Center one or multiline text in TextGadget [Resolved]

Posted: Thu Oct 02, 2014 5:48 pm
by chi
hehe thanks kwai, you've made my day :D

Re: Center one or multiline text in TextGadget [Resolved]

Posted: Sat Oct 04, 2014 7:24 pm
by Kwai chang caine
DK_PETER wrote:The code below centers the text just fine.
It's surprising, me the line is not center, on XP PRO SP3 :wink:
chi wrote:hehe thanks kwai, you've made my day :D
Thanks !!!! :D
It's exactely here for that :lol: :lol: