TextSetContent

Syntax

Success = TextSetContent(Text, Content$)

Description

Updates the text string content of an existing text object.

Parameters

Text
The handle of the text object to modify.

Content$
The new string content for the text object.

Return Value

Returns #True if the content was successfully updated, or #False if the text handle was invalid.

Remarks

Changing the content invalidates the previous text layout calculations. The width and height of the text might change, potentially requiring a layout update of the parent container if the widget size depends on the text size.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Global MyText, Counter

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw)
    DrawClear(RGB(240, 240, 240), 1)
    DrawTxt(MyText, 10, 10, 0)
EndProcedure

Procedure AnimationUpdate(Window, EventType, *EventData.PG_EventAnimate)
    Counter + 1
    TextSetContent(MyText, "Counter: " + Str(Counter))
    WindowRedraw(Window)
EndProcedure

MyWindow = CreateWindow(0, 0, 200, 100, "Text Content Update")

If MyWindow
    MyText = CreateText("Counter: 0", "Arial", 14)
    AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler())
    AddEventHandler(MyWindow, #PG_Event_Animate, @AnimationUpdate())
    StartAnimation(MyWindow, 1, 0, 10) ; Update ~10 times/sec

    WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
    Repeat: Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
    FreeText(MyText)
EndIf

StopProGUI()

See Also

CreateText, TextGetContent, DrawTxt

Supported OS

Windows, Linux