学ぶ
エンジンクラス
TextBox

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


コードサンプル
テキストボックスの秘密の単語
-- このコードをテキストボックス内の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
コードサンプル
テキストボックスの選択
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
コードサンプル
テキストボックスの選択
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():()
戻り値
()
コードサンプル
テキストボックスのフォーカスを取得
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
戻り値
()
コードサンプル
テキストボックスのフォーカスを解除
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)
テキストボックス.FocusLost1
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("エンターが押されたためフォーカスが失われました!")
else
print("エンターが押されなかったためフォーカスが失われました")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
機能: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。