TextBox

แสดงที่เลิกใช้งานแล้ว

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

กล่องเรื่อง ข้อความข้อมูลเข้า ช่วยให้ผู้เล่นให้ข้อมูลข้อความได้ มันจะทำงานเหมือนกับ TextButton เดียว ยกเว้นว่า TextBox เดียวสามารถวางในโฟก

  • หากไม่มีข้อความ PlaceholderText จะปรากฏขึ้น นี่เป็นการเรียกร้องผู้เล่นของประเภทหรือรูปแบบของข้อมูลที่พวกเขาควรป้อน
  • ตามปกติ, คุณสมบัติ ClearTextOnFocus จะเปิดใช้งานและรับประกันว่าไม่มีข้อความเมื่อการ TextBox มุ่งเน้นไปที่นั้น นี่อาจไม่เป็นสิ่งที่ต้องการสำหรับข้อความที่ผู้เล่นสามารถเปลี่ย
  • สมบัติ MultiLine ช่วยให้ผู้เล่นสามารถป้อนข้อความหลายสายด้วยตัวอักษรใหม่ ( \n )

Class. Context Action Service เคารพตัวอักษรการเข้าถึง TextBox และจะป้องกันการกดปุ่มเมาส์ที่เกิดขึ้นโดยตรงจากการผูกปุ่มด้วย ContextActionService:BindAction() และเหตุการณ์ที่เกี่ยวข้องอื่

สถานะโฟกัส

มันเป็นไปได้ที่จะตรวจจับและเปลี่ยนสถานะโฟกัสของ TextBox:

  • คุณสามารถใช้ CaptureFocus เมื่อปรากฏการแชทเพื่อให้ผู้เล่นไม่ต้องคลิกที่ TextBox เมื่อมันกลายเป็นพร้อมใช้งาน; คุณสามารถ
  • คุณสามารถตรวจจับว่ามี TextBox บางอันอยู่ในโฟกัสโดยใช้ IsFocused หรือ alternatively UserInputService:GetFocusedTextBox() สามารถใช้เพื่อตรวจจับว่ามี TextBox ใด ๆ อยู่ในโฟกัส
  • เมื่อผู้เล่นทำการป้อนข้อความเสร็จสิ้นแล้ว กิจกรรม FocusLost จะปรากฏขึ้น แสดงว่าผู้ใช้กด Enter เพื่อ
  • การเล่นเกมReleaseFocus ของ TextBox เพื่อให้การป้อนข้อมูลของผู้เล่นกลับสู่เกมของคุณ

การแก้ไขข้อความ

การเลือกข้อความใน TextBox สนับสนุนการเลือกข้อความผ่านคุณสมบัติของมัน CursorPosition และ SelectionStart โดยใช้ Class.Object:GetPropertyChangedSignal()|GetPropertyChangedSpell

การกรองข้อความของผู้ใช้เป็นข้อความของผู้ใช้เป็นข้อความของผู้ใช้เป็นข้อความของผู้ใช้เป็นข้อความของผู้ใช้เป็นข้อความของผู้ใช้เป็นข้อความของผ

ตัวอย่างโค้ด

This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.

TextBox Secret Word

-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
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 = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

สรุป

คุณสมบัติ

  • อ่านพร้อมๆ กัน

    กำหนดว่าการคลิกที่ TextBox จะล้างสมบัติของมัน TextBox.Text

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    กำหนดค่าเลื่อนของตัวอักษรในบาทหลวงหรือ -1 หากไม่มีเลื่อน

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดตัวอักษรที่ใช้เพื่อเรนเดอร์ข้อความ

  • อ่านพร้อมๆ กัน

    กำหนดตัวอักษรที่ใช้เพื่อเรนเดอร์ข้อความ

  • อ่านพร้อมๆ กัน

    ปรับแต่งการจัดตำแหน่งของข้อความใน TextBox

  • อ่านพร้อมๆ กัน

    จํานวนสูงสุดของโกรมที่ TextBox สามารถแสดงได้

  • อ่านพร้อมๆ กัน

    เมื่อตั้งค่าเป็น true ตัวอักษรใน TextBox สามารถเคลื่อนไปยังหลายสตรอกได้ นี่ช่วยให้ผู้เล่นใช้ปุ่ม Enter เพื่อเคลื่อนไปยังสตรอกใหม่

  • อ่านพร้อมๆ กัน
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    ตั้งค่าสีข้อความที่ใช้เมื่อยังไม่มีข้อความใน TextBox

  • อ่านพร้อมๆ กัน

    ตั้งค่าข้อความที่ปรากฏเมื่อยังไม่มีข้อความใด ๆ ใน TextBox

  • อ่านพร้อมๆ กัน

    กำหนดว่า TextBox จะเรนเดอร์สตริง TextBox.Text โดยใช้การจัดรูปแบบข้อความที่รวดเร็ว

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งเริ่มต้นของการเลือกข้อความ หรือ -1 หากไม่มีข้อความใด ๆ เลือก

  • อ่านพร้อมๆ กัน

    ถ้าตั้งค่าเป็น true ให้ใส่ตัวอักษรที่พูดถูกต้องบนแพลตฟอร์มจะใช้แทนคีย์บอร์ดที่อยู่ในตัวของ Roblox

  • อ่านพร้อมๆ กัน

    กำหนดสตริงที่เรนเดอร์โดยส่วนประกอบ UI

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ขนาดข้อความของส่วนหนึ่งของ UI ในออเฟ็ต

  • อ่านพร้อมๆ กัน

    กำหนดสีของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    กำหนดว่าผู้ใช้สามารถเปลี่ยน Text ได้หรือไม่

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ว่าข้อความนี้ตรงตามข้อกำหนดของ TextBox หรือไม่

  • อ่านพร้อมๆ กัน

    เปลี่ยนว่าตัวอักษรจะปรับให้เข้ากับวัตถุ GUI ที่เรนเดอร์มัน

  • อ่านพร้อมๆ กัน

    กำหนดความสูงของตัวอักษรในออเฟ็ต

  • อ่านพร้อมๆ กัน

    กำหนดสีของเส้นข้อความ (ขอบเขต)

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของเส้นข้อความ (ขอบเขต)

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน

    ควบคุมการตัดข้อความในกล่องข้อความนี้

  • อ่านพร้อมๆ กัน

    กำหนดว่าความหนาของข้อความเรียบร้อยไปยังหลายบรรทัดภายในพื้นที่ของ GUI หน้า และตัดข้อความเกิน

  • อ่านพร้อมๆ กัน

    กำหนดการจัดตำแหน่งของข้อความที่เรนเดอร์

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งการจัดตั้งของเนื้อหาที่เรนเดอร์

คุณสมบัติรับทอดมาจากGuiObject
  • อ่านพร้อมๆ กัน

    กำหนดว่ารูปแบบนี้สามารถรับข้อมูลการป้อนของผู้ใช้ได้หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดจุดเริ่มต้นของ GuiObject สัมพันธ์กับขนาดอันตามตัวเลข

  • อ่านพร้อมๆ กัน

    กำหนดว่าจะมีการปรับขนาดหรือไม่ขึ้นอยู่กับเนื้อหาของลูก

  • อ่านพร้อมๆ กัน

    กำหนดสีพื้นหลัง GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของพื้นหลังและขอบเขตของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดสีของขอบ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดวิธีการที่ GuiObject ขอบเขตถูกวางโดยเฉลี่ยกับขนาดของมัน

  • อ่านพร้อมๆ กัน

    กำหนดความกว้างของพิกเซลของ GuiObject รอบ

  • อ่านพร้อมๆ กัน

    กำหนดว่าควรเรนเดอร์หรือไม่ GuiObjects ภายนอกขอบเขตของรูปปั้น GUI ระดับพ่อของคุณ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดว่าผู้เล่นกดเมาส์บน GuiObject หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiButton สามารถใช้งานได้หรือไม่ หรือว่า GuiState ของ GuiObject กําลังเปลี่ยนแปลงหรือไม่

  • อ่านพร้อมๆ กัน

    ควบคุมลำดับการเรียงลำดับของ GuiObject เมื่อใช้กับ UIGridStyleLayout

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะได้รับการเลือกเมื่อเครื่องยนต์ผู้ควบคุมเลื่อนลง

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนซ้าย

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนไปทางขวา

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนขึ้น

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งพิกเซลและตำแหน่งเศษเส้นของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดจำนวนองศาที่ GuiObject หมุน

  • อ่านพร้อมๆ กัน

    กำหนดว่า GUI สามารถเลือกได้โดย gamepad หรือไม่

  • อ่านพร้อมๆ กัน

    เปลี่ยนแปลงการตกแต่งการเลือกที่ใช้สำหรับแพดพันเกม

  • อ่านพร้อมๆ กัน

    ลำดับของ GuiObjects ที่เลือกโดย UI เกมแพด.

  • อ่านพร้อมๆ กัน

    กำหนดขนาดพิกเซลและขนาดพิกเซลของ GuiObject

  • อ่านพร้อมๆ กัน

    ตั้งค่า Size แกนที่ Class.GuiObject จะสร้างบน, สัมพันธ์กับขนาดของพ่อของมัน.

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
    เลิกใช้แล้ว

    สมบัติสัมพันธ์ผสมของ BackgroundTransparency และ TextTransparency

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiObject และบุตรหลานของมันจะถูกเรนเดอร์หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดลำดับที่เรนเดอร์ GuiObject เมื่อเป็นคู่กับคนอื่น

คุณสมบัติรับทอดมาจากGuiBase2d
  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายตำแหน่งหน้าจอที่เป็นไปเลยของรายการ UI ในพิกเซล

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายการหมุนเวียนหน้าจริงของ UI โดยองศา

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายขนาดหน้าจอที่เป็นไปจริงของรายการ UI

  • อ่านพร้อมๆ กัน

    เมื่อตั้งค่าเป็น true จะใช้การแปลภาษาใน GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    การอ้างอิงถึง LocalizationTable ที่จะใช้ในการประยุกต์การแปลอัตโนมัติสู่ GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวลง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพานเกมในแนวโน้มทางซ้าย

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักเกมในทิศทางที่ถูกต้อง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวตั้งขึ้น

  • อ่านพร้อมๆ กัน

    ช่วยให้คุณสามารถปรับแต่งการเคลื่อนไหวของแผงควบคุมเกม

วิธีการ

  • บังคับให้ลูกค้ามุ่งเน้นไปที่ TextBox

  • กลับ true ถ้ากล่องข้อความมุ่งเน้นหรือ false ถ้าไม่

  • ReleaseFocus(submitted : bool):void

    บังคับให้ลูกค้าให้ TextBox ออก

วิธีการรับทอดมาจากGuiObject

อีเวนต์

อีเวนต์รับทอดมาจากGuiObject
  • เกิดขึ้นเมื่อผู้ใช้เริ่มต้นใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้เปลี่ยนวิธีการโต้ตอบผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มกล้อง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้หยุดใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ไปที่องค์ประกอบ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ออกจากส่วน GUI

  • การเพิ่มเติมเมื่อผู้ใช้เคลื่อนเมาส์ไปยัง GUI เมื่ออยู่ภายในส่วนหนึ่งของ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์กลับเมื่อเมาส์อยู่เหนือ GUI เอเจนต์

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์ไปข้างหน้าเมื่อเมาส์อยู่เหนือรายการ GUI

  • จุดเกิดเหตุเมื่อ GuiObject ได้รับการโฟกัสด้วย Gamepad ตัวเลือก

  • ไฟร์เมื่อ Gamepad เลือกเปลี่ยนโฟกัสไปที่ GuiObject

  • เกิดขึ้นเมื่อผู้เล่นเริ่มต้น ดำเนินการต่อและหยุดการกด UI เป็นเวลานาน

  • TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นยกนิ้วของพวกเขาบนองค์ประกอบ UI

  • TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เปิดเมื่อผู้เล่นทำการเลื่อนหรือดึงด้วยนิ้วสองนิ้วบน UI

  • TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการหมุนโดยใช้นิ้วสองนิ้วบนรูปปั้น

  • TouchSwipe(swipeDirection : Enum.SwipeDirection,numberOfTouches : number):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสไนเปอร์บนองค์ประกอบ UI

  • TouchTap(touchPositions : Array):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสายตาในส่วน UI

อีเวนต์รับทอดมาจากGuiBase2d
  • SelectionChanged(amISelected : bool,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal

    เกิดขึ้นเมื่อเลือกแผงควบคุมเกมเคลื่อนไปยัง, ออกหรือเปลี่ยนแปลงใน GuiBase2d หรือ GuiObjects ต้นได้

คุณสมบัติ

ClearTextOnFocus

อ่านพร้อมๆ กัน

กำหนดว่าการคลิกที่ TextBox จะล้างสมบัติ TextBox.Text ของมัน

ContentText

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

CursorPosition

อ่านพร้อมๆ กัน

ตําแหน่งของเครื่องมือจัดการข้อความ กําหนดความเสียหายของเครื่องมือจัดการข้อความในบาทหรือ -1 หาก TextBox ไม่ได้รับการ

ควรเป็นไปตามที่เห็นว่าหน่วยของคุณคือ บาท และว่าหลายตัวอักษรในระบบ Unicode เช่น emoji ยาวกว่า 1 บาท อินสแตนซ์TextBox "สวัส

ตัวอย่างโค้ด

This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().

TextBox Selections

local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)
ซ่อนอยู่
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัติข้อมูลแฟ้นต์เลือกหนึ่งในหลายรายการ fonts ที่ UI จะเรนเดอร์ข้อความของมันด้วย บางตัวอักษรมีตัวอักษรขนาดใหญ่, ตัวอักษรลอตเต้นและ/หรือตัวอักษรเบา (เนื่องจากไม่

ยกเว้นตัวอักษร "Legacy" ตัวอักษรแต่ละตัวจะเรนเดอร์ข้อความด้วยความสูงเส้นข้ามเส้นเท่ากับคุณสมบัติ TextBox.TextSize ตัว "Code" เป็นตัวอักษรแบบโ

คุณสมบัตินี้ได้รับการซิงค์กับคุณสมบัติ TextBox.FontFace เมื่อการตั้งค่าตัวอักษร ตัวอักษรจะตั้งค่าเป็น Font.fromEnum(value)

ตัวอย่างโค้ด

This code sample sets a parent TextLabel's Font and Text properties to all the different fonts available.

Cycle Font

local textLabel = script.Parent
while true do
-- Iterate over all the different fonts
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
end

This code sample renders a list of all the available fonts.

Show All Fonts

local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end

FontFace

อ่านพร้อมๆ กัน

สมบัติข้อมูลตัวอักษรใกล้เคียงกับสมบัติข้อมูลตัวอักษรในรายการตัวอักษร แต่สามารถตั้งค่าตัวอักษรที่ไม่มีอยู่ในรายการตัวอักษร

คุณสมบัตินี้ได้รับการซิงค์กับคุณสมบัติ TextBox.Font เมื่อตั้งค่าFontFace ฟอนต์จะตั้งค่าตามค่าตรรกะที่ตรงกัน หรือไปที่ Enum.Font.Unknown หากไม่มีคู่

LineHeight

อ่านพร้อมๆ กัน

ควบคุมความสูงของตัวอักษรโดยเป็นจำนวนหลายของขนาดตัวอักษรใน TextBox โดยการปรับเปลี่ยนความสามารถระหว่างตัวอักษรของข้อความใน Class.Toolbar ตัวอักษรที่มีความสามารถอยู่ในช่วงตั

MaxVisibleGraphemes

อ่านพร้อมๆ กัน

คุณสมบัตินี้ควบคุมจำนวนสูงสุดของโกราเมม (หรือหน่วยข้อความ) ที่ปรากฏบน TextBox ไม่ว่าจะเป็นการแสดง TextBox.PlaceholderText หรือ TextBox.Text

การเปลี่ยนแปลงสมบัติจะไม่เปลี่ยนตำแหน่งหรือขนาดของเหลี่ยมที่มองเห็นได้ - การจัดเรียงจะถูกคำนวณเป็นเหมือนเหลี่ยมทั้งหมดมองเห็นได้

การตั้งค่าสมบัติสู่ -1 จะปิดใช้งานขีดจำกัดและแสดงทั้งหมดของ TextBox.Text

MultiLine

อ่านพร้อมๆ กัน

เมื่อตั้งค่าเป็น true ตัวอักษรใน TextBox สามารถเคลื่อนไปยังหลายสตรอกได้ นี่ช่วยให้ผู้เล่นใช้ปุ่ม Enter เพื่อเคลื่อนไปยังสตรอกใหม่

OpenTypeFeatures

อ่านพร้อมๆ กัน

OpenTypeFeaturesError

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

PlaceholderColor3

อ่านพร้อมๆ กัน

ตั้งค่าสีข้อความที่ใช้เมื่อยังไม่มีข้อความใน TextBox

PlaceholderText

อ่านพร้อมๆ กัน

ตั้งค่าข้อความที่ปรากฏเมื่อยังไม่มีข้อความใด ๆ ใน TextBox

RichText

อ่านพร้อมๆ กัน

สมบัตินี้กำหนดว่า TextBox จะเรนเดอร์สตริง TextBox.Text โดยใช้การจัดรูปแบบข้อความที่เรียบง่าย ข้อความริชใช้ป้ายชื่อเรียบง่ายในการกำหนดตำแหน่งของสตริงในตัวหนังสือของต

เพื่อใช้ข้อความแบบรวมอยู่ในตัวอักษร TextBox.Text เพียงแค่รวมแท็กการจัดรูปแบบในสตริง Class.Toolbar.Text

หมายเหตุว่าเมื่อ TextBox มีคุณสมบัตินี้เปิดอยู่และกล่องได้รับการโฟกัส ผู้ใช้จะสามารถแก้ไขและใช้งานกับสตริงรูปแบบทั้งหมดรวมทั้งแท็กทั้งหมด เมื่อโฟกัสสูญหายไป เนื

SelectionStart

อ่านพร้อมๆ กัน

กำหนดตำแหน่งเริ่มต้นของตัวเลือกข้อความหรือ -1 หาก TextBox ไม่มีขอบเขตของข้อความที่เลือก หากค่านี้เป็น -1 หรือเท่ากับ Class.Toolbar.CursorPosition|CursorPosition</

ตัวอย่างโค้ด

This code sample demonstrates reading the current selection of a TextBox using CursorPosition() and SelectionStart().

TextBox Selections

local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No selection")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('The selection is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput

อ่านพร้อมๆ กัน

ถ้าตั้งค่าเป็น true ให้ใส่ตัวอักษรที่พูดถูกต้องบนแพลตฟอร์มจะใช้แทนคีย์บอร์ดที่อยู่ในตัวของ Roblox

Text

อ่านพร้อมๆ กัน

สมบัติคำที่เป็นสมบัติคำของสตริงจะถูกเรียกใช้โดย UI เอเลเมนต์ สมบ

มันเป็นไปได้ที่จะเรนเดอร์อิโมจิ (เช่น 😃) และสัญลักษณ์อื่น ๆ เหล่านี้ สัญลักษณ์เหล่านี้พิเศษไม่ได้รับผลกระทบจาก TextBox.TextColor3 สมบัติ

สมบัตินี้อาจมีตัวอักษรใหม่ แต่ไม่สามารถพิมพ์ตัวอักษรใหม่ในหน้าต่างของ ลักษณะ ได้ เช่นเดียวกับ อาจ มี ตัวอักษร tab แต่จะเรนเดอร์เป็นพื้นที่แทน

ตัวอย่างโค้ด

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

Fading Banner

local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

This code sample renders a list of all the available fonts.

Show All Fonts

local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

This code sample demonstrates emoji rendering using the Text property.

Emoji in Text

local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "I am feeling " .. mood .. "! " .. face
task.wait(1)
end
end

TextBounds

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

คุณสมบัติ TextBounds เท่านั้น สะท้อนขนาดของเนื้อหาที่เรนเดอร์ในออเฟ็ต ในคำอื่น หากคุณพยายามที่จะใส่ตัวอักษรในรูปสี่เหลี่ยม คุณสมบัตินี้จะสะท้อนขนาดขั้นต่ำของรูปสี่เหลี่ยมที่คุณต้องการใช้

โดยใช้ TextService:GetTextSize() , คุณสามารถคาดการณ์ว่า TextBounds จะอยู่บน TextLabel ที่มีสตริง, TextBox.Font และขนาดตัวอักษร และขนาดของเฟรม

ตัวอย่างโค้ด

This code sample dynamically resizes a TextLabel, TextButton or TextBox to match the size of its TextBounds. Try changing the minimum width/height and pasting into a LocalScript in a TextBox.

Dynamic TextBox Size

local textBox = script.Parent
-- The smallest the TextBox will go
local minWidth, minHeight = 10, 10
-- Set alignment so our text doesn't wobble a bit while we type
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.new(0, math.max(minWidth, textBox.TextBounds.X), 0, math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)

TextColor3

อ่านพร้อมๆ กัน

สมบัตินี้กำหนดสีของข้อความทั้งหมดที่เรนเดอร์โดย GUI องค์ประกอบ สมบัตินี้พร้อมกับ TextBox.Font และ

สำคัญที่ต้องเข้าใจว่าข้อความนี้อ่านได้ง่ายโดยผู้เล่น! ตรวจสอบให้แน่ใจว่าสีของข้อความนี้มีความเป็นกระจุกกระจายน้อยเกือบ

ตัวอย่างโค้ด

This code sample, when placed within a TextBox, will turn the text color red if the typed string contains no vowels (A, E, I, O or U).

Vowel Detector

local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Check for vowels
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Red
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

This code sample creates a password-like interface for a TextBox, giving visual feedback on the player's input.

TextBox Secret Word

-- Place this code in a LocalScript inside a TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- white
local colorWrong = Color3.new(1, 0, 0) -- red
local colorCorrect = Color3.new(0, 1, 0) -- green
-- Initialize the state of the textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "What is the secret word?"
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 = "ACCESS GRANTED"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESS DENIED"
textBox.BackgroundColor3 = colorWrong
end
else
-- The player stopped editing without pressing Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

This code sample makes a TextLabel or TextButton count backwards from 10, setting the text color as it does so.

Countdown Text

-- Place this code in a LocalScript within a TextLabel/TextButton
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorSoon = Color3.new(1, 0.5, 0.5) -- red
local colorDone = Color3.new(0.5, 1, 0.5) -- green
-- Loop infinitely
while true do
-- Count backwards from 10 to 1
for i = 10, 1, -1 do
-- Set the text
textLabel.Text = "Time: " .. i
-- Set the color based on how much time is left
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "GO!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

This code sample mirrors the contents of a StringValue into a TextLabel, updating and setting the color of the text as it changes.

Game State Text

local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Place a StringValue called "GameState" in the ReplicatedStorage
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- Place this code in a TextLabel
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorCountdown = Color3.new(1, 0.5, 0) -- orange
local colorRound = Color3.new(0.25, 0.25, 1) -- blue
-- We'll run this function to update the TextLabel as the state of the
-- game changes.
local function update()
-- Update the text
textLabel.Text = "State: " .. vGameState.Value
-- Set the color of the text based on the current game state
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- Pattern: update once when we start and also when vGameState changes
-- We should always see the most updated GameState.
update()
vGameState.Changed:Connect(update)

TextDirection

อ่านพร้อมๆ กัน

TextEditable

อ่านพร้อมๆ กัน

TextEditable กำหนดว่าผู้ใช้สามารถเปลี่ยนแปลง Text ผ่านการป้อนข้อมูลได้หรือไม่ มีความจำเป็นต้องปิดการใช้งาน Class.Toolbar.ClearTextOnFocus|ClearTextOn

TextFits

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

ว่าข้อความนี้ตรงตามข้อกำหนดของ TextBox หรือไม่

TextScaled

อ่านพร้อมๆ กัน

แทนที่จะใช้ TextScaled เราขอแนะนำให้คุณพิจารณาใช้ AutomaticSize วิธีการใหม่ในการขยายขนาด UI ที่จะให้ผลลัพธ์ทางวิสัยทัศน์ที่ดีที่สุด

สมบัติข้อความขนาดตัวอักษรที่เรียกขนาดของข้อความให้ใหญ่ขึ้น เมื่อเปิดใช้งานสมบัติข้อความนี้จะได้รับการเพิกเฉย TextBox.TextSize จะถูกเพิกเฉ

เมื่อใช้สำหรับ UI ของพื้นที่หน้าจอ อาจเป็นไปได้ที่จะใช้ UITextSizeConstraint เพื่อจำกัดขนาดข้อความที่เป็นไปได้

TextScaled และ AutomaticSize

แนะนำให้ผู้พัฒนาหลีกเลี่ยงการใช้ TextScaled และปรับแต่ง UI เพื่อให้สามารถใช้สมบัติสมบัติขนาดอัตโนมัติได้มากขึ้น ด้านล่างคือความแตกต่างระหว่างสองสมบัติสมบัติ:

  • TextScaled ปรับแต่งเนื้อหา (ข้อความ) เพื่อรองรับ UI โดยไม่ต้องสงสัย หากเครื่องมือปรับแต่งขนาดเล็กเกินไป บางข้อความอาจไม่อ่านได้หากเครื่องมือปรับแต่งขนาดเล็กเกินไป
  • AutomaticSize ปรับขนาด UI เพื่อรองรับเนื้อหา

ด้วยขนาดอัตโนมัติคุณสามารถปรับแต่ง UI ของคุณเพื่อรองรับเนื้อหา (ข้อความ) ในขณะที่คุณยังคงใช้ขนาดตัวอักษรที่เหมาะสม

เราแนะนำให้คุณไม่ใช้ both TextScaled และ AutomaticSize บนวัตถุเดียวกัน หากคุณใช้ both โปรพีดีพี่ี่:

  • AutomaticSize กำหนดจำนวนพื้นที่สูงสุดที่ GuiObject สามารถใช้ได้ (ในกรณีนี้คือข้อความ)
  • TextScaled ใช้พื้นที่ที่กำหนดโดย AutomaticSize เพื่อปรับขนาดตัวอักษรให้เหมาะกับพื้นที่ที่มีอยู่ ซึ่งจะขยายไปยังขนาดตัวอักษรสูงสุด (100) หากไม่มีข้อจํากัด
  • ผลลัพธ์สุดท้ายจะเป็น: ตัวอักษรไปที่ขนาดตัวอักษร 100 และวัตถุ UI จะขยายเพื่อให้เข้ากับตัวอักษรนั้น

การใช้ both AutomaticSize และ TextScaled ในเวลาเดียวกันอาจทำให้เกิดความแตกต่างขนาดที่มากเกินไปเมื่อเวลา AutomaticSize ปิด

ตัวอย่างโค้ด

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextSize

อ่านพร้อมๆ กัน

สมบัติขนาดข้อความ กำหนดความสูงในออเฟ็ตของข้อความเดียว หน่วยอยู่ในออเฟ็ต ไม่ใช่จุด (ซึ่งใช้ในโปรแกรมการแก้ไขข้อความส่วนใหญ่) ตัวอักษร "รุ่นมรดก" ไม่รองรับสมบัตินี้

ตัวอย่างโค้ด

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextStrokeColor3

อ่านพร้อมๆ กัน

สี TextStrokeColor3 ตั้งค่าสีของเส้นหรือเงาของข้อความที่เรนเดอร์ สีนี้และ TextBox.TextStrokeTransparency กำหนดสมบัติสมบัติของเส้นหรือเงา

การเรนเดอร์ของเนื้อหานี้จะแสดงก่อนที่จะเป็นข้อความปกติและเป็นเพียง 4 การเรนเดอร์ของข้อความเดียวกันใน +/- 1 พิกเซลออฟเซ็ตในแต่ละทิศทาง การเรนเดอร์ของเนื้อหานี

ตัวอย่างโค้ด

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextStrokeTransparency

อ่านพร้อมๆ กัน

สมบัติคุณสมบัติ TextStrokeTransparency ตั้งค่าความโปร่งใสของเส้นหรือเงาของข้อความที่เรนเดอร์ได้ คุณสมบัตินี้และ TextBox.TextStrokeColor3 กำหนดสมบัติคุณสมบัติของเส้นข้อความ

การเรนเดอร์ลายเนื้อข้อความเป็นสีก่อนที่จะเป็นข้อความปก

ตัวอย่างโค้ด

This code sample oscillates a TextLabel's TextStrokeTransparency so that it blinks the highlight of a text.

Text Highlight Oscillation

local textLabel = script.Parent
-- How fast the highlight ought to blink
local freq = 2
-- Set to yellow highlight color
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sin oscillates from -1 to 1, so we change the range to 0 to 1:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextTransparency

อ่านพร้อมๆ กัน

สมบัติข้อความสื่อผลลัพธ์โดย UI จะกำหนดความโปร่งใสของข้อความทั้งหมดที่เรนเดอร์โดยเอลเมนต์ UI นี้ สมบัติข้อความนี้จะปรากฏหลังจา

ตัวอักษรที่เรืองแสงขึ้นเมื่อใช้ for-loop เป็นวิธีที่ยอดเยี่ยมในการดึงดูดความสนใจของผู้เล่นไปยังข้อความที่ปรากฏบนหน้าจอ


-- Count backwards from 1 to 0, decrementing by 0.1
for i = 1, 0, -0.1 do
textLabel.TextTransparency = i
task.wait(0.1)
end

ตัวอย่างโค้ด

This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.

Fading Banner

local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end

This code sample repeatedly tweens a TextLabel's TextSize from 5 to 100 and fades out the text as it grows in size.

"Kaboom!" Text

local textLabel = script.Parent
textLabel.Text = "Kaboom!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextTruncate

อ่านพร้อมๆ กัน

ควบคุมการตัดข้อความในกล่องข้อความนี้

TextWrapped

อ่านพร้อมๆ กัน

เมื่อเปิดใช้งานสมบัติสมบัตินี้จะเรนเดอร์ข้อความในหลายบรรทัดภายในพื้นที่ของ GUI เพื่อให้ TextBox.TextBounds ไม่เกินขีดจำกัด GuiBase2d.AbsoluteSize ของ GUI เอเลมนต์

สิ่งนี้สามารถดำเนินการได้โดยการแบ่งตัวอักษรยาวเป็นหลายตัวอักษร การแบ่งตัวอักษรจะเริ่มต้นด้วยช่องว่างขาว; หากคำยาวไม่ได้ถูกแบ่งเป็นหลายสาย คำนั้นจะถูกแบ่งเป็นหลายสาย

หากเกิดการแบ่งตัวอักษรเกินความสูงของเนื้อหา (ส่วนประกอบ Y ของ TextBox.TextBounds ) จะทำให้ความสูงของเนื้อหาเกินความสูงขององค์ประกอบ (ส่วนประกอบ Y ของ GuiBase2d.AbsoluteSize )

ตัวอย่างโค้ด

This code sample demonstrates TextWrap by spelling out a long chunk of text progressively. If the text doesn't fit, it turns a different color.

Long Text Wrapping

local textLabel = script.Parent
-- This text wrapping demo is best shown on a 200x50 px rectangle
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- Some content to spell out
local content = "Here's a long string of words that will "
.. "eventually exceed the UI element's width "
.. "and form line breaks. Useful for paragraphs "
.. "that are really long."
-- A function that will spell text out two characters at a time
local function spellTheText()
-- Iterate from 1 to the length of our content
for i = 1, content:len() do
-- Get a substring of our content: 1 to i
textLabel.Text = content:sub(1, i)
-- Color the text if it doesn't fit in our box
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- Black
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- Red
end
-- Wait a brief moment on even lengths
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- Spell the text with scale/wrap off
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with wrap on
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- Spell the text with text scaling on
-- Note: Text turns red (TextFits = false) once text has to be
-- scaled down in order to fit within the UI element.
textLabel.TextScaled = true
-- Note: TextWrapped is enabled implicitly when TextScaled = true
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextXAlignment

อ่านพร้อมๆ กัน

TextXAlignment กำหนดการจัดตำแหน่งของเนื้อหาในช่องว่างของ UI โดยใช้หน้าเนื้อหา (X-axis) ตัวอักษร มันทำงานได้เช่นเดียวกับสมบัติคำแนะนำของ CSS โดยมีค่าซ้าย ขวา แ

สมบัตินี้ใช้ร่วมกับ TextBox.TextYAlignment เพื่อระบุตำแหน่งข้อความในแกนทั้งสองอย่างเต็มที่ สมบัตินี้จะไม่ส่งผลต่อสมบัติที่อ่านเท่านั้น TextBox.TextBounds และ

ตัวอย่างโค้ด

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

Text Alignment

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- Iterate over both TextXAlignment and TextYAlignment enum items
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end

TextYAlignment

อ่านพร้อมๆ กัน

TextYAlignment กำหนดความสมดุลแนวตั้ง (Y เห�ียน) ของเนื้อหาที่เรนเดอร์ในพื้นที่ UI เอเจนต์ สำหรับด้านบนและด้านล่าง เนื้อหาจะถูกเรนเดอร์ให้เหมือนเป็นขอบของ UI

สมบัตินี้ใช้ร่วมกับ TextBox.TextXAlignment เพื่อระบุตำแหน่งข้อความในแกนทั้งสองอย่างเต็มที่ สมบัตินี้จะไม่ส่งผลต่อสมบัติที่อ่านเท่านั้น TextBox.TextBounds และ

ตัวอย่างโค้ด

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

Text Alignment

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- Iterate over both TextXAlignment and TextYAlignment enum items
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end

วิธีการ

CaptureFocus

void

บังคับให้ลูกค้ามุ่งเน้นไปที่ TextBox


ส่งค่ากลับ

void

ตัวอย่างโค้ด

This code sample causes the client to focus on the parent TextBox when the Q key is pressed by the player.

TextBox:CaptureFocus

local ContextActionService = game:GetService("ContextActionService")
local ACTION_NAME = "FocusTheTextBox"
local textBox = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_NAME and inputState == Enum.UserInputState.End then
textBox:CaptureFocus()
end
end
ContextActionService:BindAction(ACTION_NAME, handleAction, false, Enum.KeyCode.Q)

IsFocused

กลับ true ถ้ากล่องข้อความมุ่งเน้นหรือ false ถ้าไม่


ส่งค่ากลับ

ReleaseFocus

void

บังคับให้ลูกค้าละเลย TextBox ลูกค้าสามารถใช้ตัวประกาศเวลาเพื่อเปลี่ยนค่า <a href="/reference/engine/datatypes">TextBox</a> ในอีเวนต์ <a href="/reference/engine/datatypes">Class. Chelten. FocusLost</a> ได้

รายการนี้ควรใช้กับ LocalScript เพื่อให้สามารถทำงานได้ตามที่คาดหวังในโหมดออนไลน์

รหัสด้านล่างจะบังคับให้ลูกค้าเปลี่ยนโฟกัสออกจาก 'Texture' 5 วินาทีหลังจากที่มันเลือก:


local TextBox = script.Parent
TextBox.Focused:Connect(function()
wait(5)
TextBox:ReleaseFocus()
end)

โปรดทราบว่าตัวอย่างด้านบนนี้เข้าใจว่ามันอยู่ใน LocalScript เป็นลูกของ TextBox

พารามิเตอร์

submitted: bool
ค่าเริ่มต้น: false

ส่งค่ากลับ

void

ตัวอย่างโค้ด

The code shown below will force the client to unfocus the 'TextBox' 5 seconds after it's selected:

TextBox:ReleaseFocus

local textBox = script.Parent
local function onFocused()
task.wait(5)
textBox:ReleaseFocus()
end
textBox.Focused:Connect(onFocused)

อีเวนต์

FocusLost

เปิดให้เมื่อลูกค้าปล่อยให้โฟกัสออกจาก TextBox - โดยปกติเมื่อลูกค้าคลิก/แตะนอก TextBox

สามารถใช้ร่วมกับ TextBox.Focused เพื่อติดตามเมื่อ TextBox ได้รับการโฟกัสและสูญเสียโฟกัส

ดูเพิ่มเติมที่ UserInputService.TextBoxFocused และ UserInputService.TextBoxFocusReleased สำหรับคุณสมบัติที่เกี่ยวข้องกับบริการ <Class.UserInputService>

เหตุการณ์นี้จะเกิดขึ้นเฉพาะเมื่อใช้ใน LocalScript

พารามิเตอร์

enterPressed: bool

บูลีนที่ระบุว่าผู้ใช้กด Enter เพื่อสูญเสียโฟกัส ( จริง ) หรือไม่ ( ปลอม )

inputThatCausedFocusLoss: InputObject

ตัวอย่าง InputObject ที่แสดงถึงประเภทของการป้อนข้อมูลที่ทำให้ TextBox สูญเสียโฟกัส


ตัวอย่างโค้ด

The example shown below will print "Focus was lost because enter was pressed!" whenever the TextBox loses focus as a result of the enter key being pressed.

TextBox.FocusLost1

local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("Focus was lost because enter was pressed!")
else
print("Focus was lost without enter being pressed")
end
end
textBox.FocusLost:Connect(focusLost)

This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox loses focus, the example prints either:

  1. "Player pressed Enter" - if the TextBox lost focus because the player pressed the Enter key. or
  2. "Player pressed InputObject.KeyCode" - where "KeyCode" is the InputObject KeyCode property of the input that caused the TextBox to lose focus. For example, pressing the Escape (esc) key to exit TextBox focus returns an InputObject instance with the KeyCode 'InputObject.Escape'.
FocusLost

local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Player pressed Enter")
else
print("Player pressed", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)

Focused

เกิดขึ้นเมื่อ TextBox ได้รับความสนใจ - โดยปกติเมื่อลูกค้าคลิก/แตะที่ TextBox เพื่อเริ่มการป้อนข้อความ

สามารถใช้ร่วมกับ TextBox.FocusLost เพื่อติดตามเมื่อ TextBox ได้รับการโฟกัสและสูญเสียโฟกัส

ดูเพิ่มเติมที่ UserInputService.TextBoxFocused และ UserInputService.TextBoxFocusReleased สำหรับคุณสมบัติที่เกี่ยวข้องกับบริการ <Class.UserInputService>

เหตุการณ์นี้จะเกิดขึ้นเฉพาะเมื่อใช้ใน LocalScript


ตัวอย่างโค้ด

This example works when placed in a LocalScript that is the child of a TextBox. When the TextBox gains focus, the example prints "Focus".

Focus

local textBox = script.Parent
local function onFocused()
print("Focused")
end
textBox.Focused:Connect(onFocused)

ReturnPressedFromOnScreenKeyboard