Apprendre
Classe de moteur
TextBox

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Échantillons de code
TexteSecret du TextBox
-- Placez ce code dans un LocalScript à l'intérieur d'un TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- blanc
local colorWrong = Color3.new(1, 0, 0) -- rouge
local colorCorrect = Color3.new(0, 1, 0) -- vert
-- Initialisez l'état du textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Quel est le mot secret?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACCÈS AUTORISÉ"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCÈS REFUSÉ"
textBox.BackgroundColor3 = colorWrong
end
else
-- Le joueur a cessé d'éditer sans appuyer sur Entrée
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

Référence API
Propriétés
ClearTextOnFocus
Lecture parallèle
Capacités : UI
TextBox.ClearTextOnFocus:boolean

ContentText
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextBox.ContentText:string

CursorPosition
Lecture parallèle
Capacités : UI
TextBox.CursorPosition:number
Échantillons de code
Sélections de Zone de Texte
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Aucune sélection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La sélection est : "', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Caché
Non répliqué
Lecture parallèle
Capacités : UI
TextBox.Font:Enum.Font

FontFace
Lecture parallèle
Capacités : UI
TextBox.FontFace:Font

FontSize
Déprécié

LineHeight
Lecture parallèle
Capacités : UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Lecture parallèle
Capacités : UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Lecture parallèle
Capacités : UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Lecture parallèle
Capacités : UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Lecture parallèle
Capacités : UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Lecture parallèle
Capacités : UI
TextBox.PlaceholderText:string

RichText
Lecture parallèle
Capacités : UI
TextBox.RichText:boolean

SelectionStart
Lecture parallèle
Capacités : UI
TextBox.SelectionStart:number
Échantillons de code
Sélections de Zone de Texte
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Aucune sélection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La sélection est : "', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Lecture parallèle
Capacités : UI
TextBox.ShowNativeInput:boolean

Text
Lecture parallèle
Capacités : UI
TextBox.Text:string

TextBounds
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextBox.TextBounds:Vector2

TextColor
Déprécié

TextColor3
Lecture parallèle
Capacités : UI
TextBox.TextColor3:Color3
Échantillons de code
Détecteur de Voyelles
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Vérifier les voyelles
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Noir
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rouge
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Lecture parallèle
Capacités : UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Lecture parallèle
Capacités : UI
TextBox.TextEditable:boolean

TextFits
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : UI
TextBox.TextFits:boolean

TextScaled
Lecture parallèle
Capacités : UI
TextBox.TextScaled:boolean

TextSize
Lecture parallèle
Capacités : UI
TextBox.TextSize:number

TextStrokeColor3
Lecture parallèle
Capacités : UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Lecture parallèle
Capacités : UI
TextBox.TextStrokeTransparency:number

TextTransparency
Lecture parallèle
Capacités : UI
TextBox.TextTransparency:number

TextTruncate
Lecture parallèle
Capacités : UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Déprécié

TextWrapped
Lecture parallèle
Capacités : UI
TextBox.TextWrapped:boolean

TextXAlignment
Lecture parallèle
Capacités : UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Lecture parallèle
Capacités : UI
TextBox.TextYAlignment:Enum.TextYAlignment

Méthodes
CaptureFocus
Capacités : UI
TextBox:CaptureFocus():()
Retours
()
Échantillons de code
Capturer le focus du TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Q then
textBox:CaptureFocus()
end
end)

IsFocused
Capacités : UI
TextBox:IsFocused():boolean
Retours

ReleaseFocus
Capacités : UI
TextBox:ReleaseFocus(submitted:boolean):()
Paramètres
submitted:boolean
Valeur par défaut : false
Retours
()
Échantillons de code
Libération du Focus du TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Escape and textBox.IsFocused then
textBox:ReleaseFocus()
end
end)

Événements
Focused
Capacités : UI
TextBox.Focused():RBXScriptSignal
Échantillons de code
Focus de la zone de texte
local textBox = script.Parent
textBox.Focused:Connect(function()
print("En focus !")
end)
textBox.FocusLost:Connect(function()
print("Focus perdu !")
end)

FocusLost
Capacités : UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Paramètres
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Échantillons de code
Focus de la zone de texte
local textBox = script.Parent
textBox.Focused:Connect(function()
print("En focus !")
end)
textBox.FocusLost:Connect(function()
print("Focus perdu !")
end)
PerteDeFocus
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Le joueur a appuyé sur Entrée")
else
print("Le joueur a appuyé sur", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)
TextBox.FocusLost1
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("Le focus a été perdu parce que la touche entrer a été pressée!")
else
print("Le focus a été perdu sans que la touche entrer ait été pressée")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Capacités : UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.