Center one or multiline text in TextGadget [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Center one or multiline text in TextGadget [Resolved]

Post 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
Last edited by Kwai chang caine on Wed Oct 01, 2014 6:01 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Center one or multiline text in TextGadget

Post by DK_PETER »

use #ES_CENTER instead of #SS_CENTERIMAGE
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: Center one or multiline text in TextGadget

Post by bobobo »

Hi there

change #SS_CENTERIMAGE to #ES_CENTER

greetz

-- wow .. a little late :mrgreen:
사십 둘 .
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Center one or multiline text in TextGadget

Post 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:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Center one or multiline text in TextGadget

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Center one or multiline text in TextGadget

Post 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
Last edited by Kwai chang caine on Wed Oct 01, 2014 5:23 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Center one or multiline text in TextGadget

Post by ts-soft »

You can remove the flag (#ES_CENTER) with the same result!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Center one or multiline text in TextGadget

Post by Kwai chang caine »

Justely...how i can modify a parameter dynamically ???

Code: Select all

SendMessage_(#Label0, #????)
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4948
Joined: Sun Apr 12, 2009 6:27 am

Re: Center one or multiline text in TextGadget

Post 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
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Center one or multiline text in TextGadget

Post 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 ?
ImageThe happiness is a road...
Not a destination
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

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

Post 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
Et cetera is my worst enemy
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post 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 !!!!!!
ImageThe happiness is a road...
Not a destination
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Center one or multiline text in TextGadget

Post 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
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

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

Post by chi »

hehe thanks kwai, you've made my day :D
Et cetera is my worst enemy
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post 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:
ImageThe happiness is a road...
Not a destination
Post Reply