Restored from previous forum. Originally posted by Metonym.
Hello.
How can I put a 'newline' into a String$ or a TextGadget?
Is it possible to change fonts (or something like center etc.) within a StringGadget or TextGaget?
Hans-Jürgen
new line in String or TextGadget
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
Hope this helps ... it uses a skeleton I have to quick build GUIs, so just focus on gadgets instructions. The only way I know is to free and create again gadgets.
I am interested if one know a better way.
;*************************************************************************
;
; Declarations
;
i.l
WindowXSize.l
WindowYSize.l
ScreenWidth.l
ScreenHeight.l
WindowXstart.l
WindowYStart.l
StatusBar.l
FontPointer.l
CharacterSet.s
EOL.s
;
; General purpose initalization
;
EOL = Chr(13) + Chr(10)
For i = 32 To 224 Step 16
For j = 0 To 15
CharacterSet = CharacterSet + Chr(i + j)
Next
CharacterSet = CharacterSet + EOL
Next
;
; Procedures
;
;
; Main starts here
;
InitKeyboard()
Result = LoadFont(0, "Gando BT", 14) ; change with any other if your system font list do not have those fonts
Result = LoadFont(1, "Arial", 12)
UseFont(0)
FontID = FontID()
FontPointer = 0
WindowXSize = 480
WindowYSize = 360
ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN)
WindowXStart = Round(ScreenWidth / 2.0, 0) - Round(WindowXSize / 2.0, 0)
WindowYStart = Round(ScreenHeight / 2.0, 0) - Round(WindowYSize / 2.0, 0)
StatusBar = #TRUE
If OpenWindow(0, WindowXStart, WindowYStart, WindowXSize, WindowYSize + 25 * StatusBar, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_BorderLess , "Main Window - Close or ESC to quit - F1 to change Gadget Font")
CreateStatusBar(0, WindowID())
;
; Preparing the drawing window context
;
Result = CreateGadgetList(WindowID())
SetGadgetFont(FontID())
StringGadget(0, 10, 10, 460, 165, "Default String Gadget text")
TextGadget (1, 10, 185, 460, 165, "Default Text Gadget text")
StartDrawing(WindowOutput())
DrawingFont(FontID)
FrontColor(0, 0, 0)
Box(0, 0, WindowXSize, WindowYSize)
BackColor(0, 0, 0)
FrontColor(255, 255, 255)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog" + EOL + CharacterSet)
SetGadgetText(1, "Voyez le brick géant que j'examine près du wharf" + EOL + CharacterSet)
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_KEY_F1)
Delay(250) ; just to avoid bouncing key event
FontPointer = 1 - FontPointer
UseFont(FontPointer)
FontID = FontID()
SetGadgetFont(FontID())
FreeGadget(0)
FreeGadget(1)
StringGadget(0, 10, 10, 460, 165, "The quick brown fox jumps over the lazy dog" + EOL + CharacterSet)
TextGadget (1, 10, 185, 460, 165, "Voyez le brick géant que j'examine près du wharf" + EOL + CharacterSet)
EndIf
Until WindowEvent() = #PB_EventCloseWindow Or KeyboardPushed(#PB_KEY_ESCAPE)
EndIf
End
;*************************************************************************
Francois Weil
14, rue Douer
F64100 Bayonne
Hope this helps ... it uses a skeleton I have to quick build GUIs, so just focus on gadgets instructions. The only way I know is to free and create again gadgets.
I am interested if one know a better way.
;*************************************************************************
;
; Declarations
;
i.l
WindowXSize.l
WindowYSize.l
ScreenWidth.l
ScreenHeight.l
WindowXstart.l
WindowYStart.l
StatusBar.l
FontPointer.l
CharacterSet.s
EOL.s
;
; General purpose initalization
;
EOL = Chr(13) + Chr(10)
For i = 32 To 224 Step 16
For j = 0 To 15
CharacterSet = CharacterSet + Chr(i + j)
Next
CharacterSet = CharacterSet + EOL
Next
;
; Procedures
;
;
; Main starts here
;
InitKeyboard()
Result = LoadFont(0, "Gando BT", 14) ; change with any other if your system font list do not have those fonts
Result = LoadFont(1, "Arial", 12)
UseFont(0)
FontID = FontID()
FontPointer = 0
WindowXSize = 480
WindowYSize = 360
ScreenWidth = GetSystemMetrics_(#SM_CXSCREEN)
ScreenHeight = GetSystemMetrics_(#SM_CYSCREEN)
WindowXStart = Round(ScreenWidth / 2.0, 0) - Round(WindowXSize / 2.0, 0)
WindowYStart = Round(ScreenHeight / 2.0, 0) - Round(WindowYSize / 2.0, 0)
StatusBar = #TRUE
If OpenWindow(0, WindowXStart, WindowYStart, WindowXSize, WindowYSize + 25 * StatusBar, #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_BorderLess , "Main Window - Close or ESC to quit - F1 to change Gadget Font")
CreateStatusBar(0, WindowID())
;
; Preparing the drawing window context
;
Result = CreateGadgetList(WindowID())
SetGadgetFont(FontID())
StringGadget(0, 10, 10, 460, 165, "Default String Gadget text")
TextGadget (1, 10, 185, 460, 165, "Default Text Gadget text")
StartDrawing(WindowOutput())
DrawingFont(FontID)
FrontColor(0, 0, 0)
Box(0, 0, WindowXSize, WindowYSize)
BackColor(0, 0, 0)
FrontColor(255, 255, 255)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog" + EOL + CharacterSet)
SetGadgetText(1, "Voyez le brick géant que j'examine près du wharf" + EOL + CharacterSet)
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_KEY_F1)
Delay(250) ; just to avoid bouncing key event
FontPointer = 1 - FontPointer
UseFont(FontPointer)
FontID = FontID()
SetGadgetFont(FontID())
FreeGadget(0)
FreeGadget(1)
StringGadget(0, 10, 10, 460, 165, "The quick brown fox jumps over the lazy dog" + EOL + CharacterSet)
TextGadget (1, 10, 185, 460, 165, "Voyez le brick géant que j'examine près du wharf" + EOL + CharacterSet)
EndIf
Until WindowEvent() = #PB_EventCloseWindow Or KeyboardPushed(#PB_KEY_ESCAPE)
EndIf
End
;*************************************************************************
Francois Weil
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by TronDoc.
CarriageReturn LineFeed doesn't work? {CHR(13)+CHR(10)}
e.g.:
crlf$ = CHR(13)+CHR(10)
myString01$ = "Now is the time"
myString02$ = "For all good men.."
newString$ = myString01$ + crlf$ + myString02$
PRINT newString$
elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE
CarriageReturn LineFeed doesn't work? {CHR(13)+CHR(10)}
e.g.:
crlf$ = CHR(13)+CHR(10)
myString01$ = "Now is the time"
myString02$ = "For all good men.."
newString$ = myString01$ + crlf$ + myString02$
PRINT newString$
elecTRONics DOCtor
{registeredPB}P150 32Mb w98/DOS/Linux NO DirX NO IE
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm