เรียนรู้
Engine Class
TextBox

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
วิธีการ
ReleaseFocus(submitted: boolean):()
เหตุการณ์
FocusLost(enterPressed: boolean,inputThatCausedFocusLoss: InputObject):RBXScriptSignal
สมาชิกที่ได้รับทอด
ตัวอย่างโค้ด
คำลับในช่องข้อความ
-- วางโค้ดนี้ใน LocalScript ภายในช่องข้อความ
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- ขาว
local colorWrong = Color3.new(1, 0, 0) -- แดง
local colorCorrect = Color3.new(0, 1, 0) -- เขียว
-- ตั้งค่าเริ่มต้นของ textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "คำลับคืออะไร?"
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 = "การเข้าถึงได้รับอนุญาต"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "การเข้าถึงถูกปฏิเสธ"
textBox.BackgroundColor3 = colorWrong
end
else
-- ผู้เล่นหยุดแก้ไขโดยไม่กด Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
ClearTextOnFocus
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.ClearTextOnFocus:boolean

ContentText
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.ContentText:string

CursorPosition
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.CursorPosition:number
ตัวอย่างโค้ด
การเลือก TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("ไม่มีการเลือก")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('การเลือกคือ:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.Font:Enum.Font

FontFace
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.FontFace:Font

FontSize
เลิกใช้แล้ว

LineHeight
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.PlaceholderText:string

RichText
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.RichText:boolean

SelectionStart
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.SelectionStart:number
ตัวอย่างโค้ด
การเลือก TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("ไม่มีการเลือก")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('การเลือกคือ:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.ShowNativeInput:boolean

Text
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.Text:string

TextBounds
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextBounds:Vector2

TextColor
เลิกใช้แล้ว

TextColor3
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextColor3:Color3
ตัวอย่างโค้ด
ตัวตรวจสอบสระ
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- ตรวจสอบหาสระ
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- สีดำ
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- สีแดง
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextEditable:boolean

TextFits
อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextFits:boolean

TextScaled
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextScaled:boolean

TextSize
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextSize:number

TextStrokeColor3
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextStrokeTransparency:number

TextTransparency
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextTransparency:number

TextTruncate
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
เลิกใช้แล้ว

TextWrapped
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextWrapped:boolean

TextXAlignment
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
อ่านพร้อมๆ กัน
ความสามารถ: UI
TextBox.TextYAlignment:Enum.TextYAlignment

วิธีการ
CaptureFocus
ความสามารถ: UI
TextBox:CaptureFocus():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
จับโฟกัส 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
ความสามารถ: UI
TextBox:IsFocused():boolean
ส่งค่ากลับ

ReleaseFocus
ความสามารถ: UI
TextBox:ReleaseFocus(submitted:boolean):()
พารามิเตอร์
submitted:boolean
ค่าเริ่มต้น: false
ส่งค่ากลับ
()
ตัวอย่างโค้ด
ปล่อยโฟกัสจาก 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)

เหตุการณ์
Focused
ความสามารถ: UI
TextBox.Focused():RBXScriptSignal
ตัวอย่างโค้ด
กล่องข้อความโฟกัส
local textBox = script.Parent
textBox.Focused:Connect(function()
print("ถูกโฟกัส!")
end)
textBox.FocusLost:Connect(function()
print("สูญเสียการโฟกัส!")
end)

FocusLost
ความสามารถ: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
พารามิเตอร์
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
ตัวอย่างโค้ด
กล่องข้อความโฟกัส
local textBox = script.Parent
textBox.Focused:Connect(function()
print("ถูกโฟกัส!")
end)
textBox.FocusLost:Connect(function()
print("สูญเสียการโฟกัส!")
end)
สูญเสียจุดโฟกัส
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("ผู้เล่นกด Enter")
else
print("ผู้เล่นกด", 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("โฟกัสถูกสูญเสียเพราะกด Enter!")
else
print("โฟกัสถูกสูญเสียโดยไม่มีการกด Enter")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
ความสามารถ: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ