Garry's Mod Wiki



A form which may be used to display text the player is meant to select and copy or alternately allow them to enter some text of their own.

Do note that at least one of your DTextEntry's parents must either be an EditablePanel or derived from it (like a DFrame, for example), else it won't be able to focus and thus be unselectable.

You must also call Panel:MakePopup on said panel or the DTextEntry will not work.


Derives methods, etc not listed on this page from TextEntry.


boolean DTextEntry:AllowInput( string char )
Called whenever the value of the panel has been updated (whether by user input or otherwise). It allows you to determine whether a user can modify the TextEntry's text. By default, this only checks whether the panel disallows numeric characters, preventing it from being edited if the value contains any. This is actually an engine hook that only works on TextEntry derived elements.
boolean DTextEntry:CheckNumeric( string strValue )
Returns whether a string is numeric or not. Always returns false if the DTextEntry:SetNumeric is set to false.
table DTextEntry:GetAutoComplete( string inputText )
Called by the DTextEntry when a list of autocompletion options is requested. Meant to be overridden.
table DTextEntry:GetCursorColor()
Returns the cursor color of a DTextEntry.
boolean DTextEntry:GetEnterAllowed()
Returns whether pressing Enter can cause the panel to lose focus. Note that a multiline DTextEntry cannot be escaped using the Enter key even when this function returns true.
number DTextEntry:GetFloat()
Returns the contents of the DTextEntry as a number.
number DTextEntry:GetInt()
Similar to DTextEntry:GetFloat, but rounds the value to the nearest integer.
boolean DTextEntry:GetNumeric()
Returns whether only numeric characters (123456789.-) can be entered into the DTextEntry.
boolean DTextEntry:GetPaintBackground()
Whether the background is displayed or not
table DTextEntry:GetPlaceholderColor()
Return current color of panel placeholder
string DTextEntry:GetPlaceholderText()
Returns the placeholder text set with DTextEntry:SetPlaceholderText.
table DTextEntry:GetTextColor()
Returns the text color of a DTextEntry.
boolean DTextEntry:GetUpdateOnType()
Returns whether the DTextEntry is set to run DTextEntry:OnValueChange every time a character is typed or deleted or only when Enter is pressed.
boolean DTextEntry:IsEditing()
Returns whether this DTextEntry is being edited or not. (i.e. has focus)
boolean DTextEntry:IsMultiline()
Determines whether or not DTextEntry is in multi-line mode. This is set with DTextEntry:SetMultiline.
Called internally by DTextEntry:OnTextChanged when the user modifies the text in the DTextEntry. You should override this function to define custom behavior when the DTextEntry text changes.
DTextEntry:OnEnter( string value )
Called whenever enter is pressed on a DTextEntry. DTextEntry:IsEditing will still return true in this callback!
Called whenever the DTextEntry gains focus.
DTextEntry:OnKeyCode( number keyCode )
Called from DTextEntry's TextEntry:OnKeyCodeTyped override whenever a valid character is typed while the text entry is focused.
Called whenever the DTextEntry lose focus.
DTextEntry:OnTextChanged( boolean noMenuRemoval )
This is used internally - although you're able to use it you probably shouldn't. Called internally when the text inside the DTextEntry changes. You should not override this function. Use DTextEntry:OnValueChange instead.
DTextEntry:OnValueChange( string value )
Called internally when the text changes of the DTextEntry are applied. (And set to the attached console variable, if one is given) See also DTextEntry:OnChange for a function that is called on every text change, even if the console variable is not updated. You should override this function to define custom behavior when the text changes. This method is called: When Enter is pressed after typing When DTextEntry:SetValue is used For every key typed - only if DTextEntry:SetUpdateOnType was set to true (default is false)
DTextEntry:OpenAutoComplete( table tab )
This is used internally - although you're able to use it you probably shouldn't. You really should be using DTextEntry:GetAutoComplete instead. Builds a DMenu for the DTextEntry based on the input table.
DTextEntry:SetCursorColor( table color )
Sets the cursor's color in DTextEntry (the blinking line).
DTextEntry:SetDisabled( boolean disabled )
We advise against using this. It may be changed or removed in a future update. Use Panel:SetEnabled instead. Disables input on a DTextEntry and greys it out visually. This differs from DTextEntry:SetEditable which doesn't visually change the textbox.
DTextEntry:SetEditable( boolean enabled )
Disables Input on a DTextEntry. This differs from DTextEntry:SetDisabled - SetEditable will not affect the appearance of the textbox.
DTextEntry:SetEnterAllowed( boolean allowEnter )
Sets whether pressing the Enter key will cause the DTextEntry to lose focus or not, provided it is not multiline. This is true by default.
DTextEntry:SetFont( string font )
Changes the font of the DTextEntry.
DTextEntry:SetHistoryEnabled( boolean enable )
Enables or disables the history functionality of DTextEntry.
DTextEntry:SetMultiline( boolean multiline )
Enables or disables the multi-line functionality of DTextEntry.
DTextEntry:SetNumeric( boolean numericOnly )
Sets whether or not to decline non-numeric characters as input. Numeric characters are 1234567890.-
DTextEntry:SetPaintBackground( boolean show )
Sets whether to show background.
DTextEntry:SetPlaceholderColor( table color = Color(128, 128, 128) )
Allow you to set placeholder color.
DTextEntry:SetPlaceholderText( string text = "nil" )
Sets the placeholder text that will be shown while the text entry has no user text. The player will not need to delete the placeholder text if they decide to start typing.
DTextEntry:SetTabbingDisabled( boolean enabled )
Sets whether or not the panel accepts tab key. Disabling tab key prevents the panel from unfocusing by mouse, however, still works for focusing to other keyboard focus.
DTextEntry:SetTextColor( table color )
Sets the text color of the DTextEntry.
DTextEntry:SetUpdateOnType( boolean updateOnType )
Sets whether we should fire DTextEntry:OnValueChange every time we type or delete a character or only when Enter is pressed.
DTextEntry:SetValue( string text )
Sets the text of the DTextEntry and calls DTextEntry:OnValueChange. The text of the DTextEntry only changes if it's not currently being typed in. If you would rather set the text regardless, use Panel:SetText.


Creates a text entry form that allows you to print messages into the local player's chat window.

concommand.Add( "test_textentry", function(ply) local frame = vgui.Create( "DFrame" ) frame:SetSize( 400, 200 ) frame:Center() frame:MakePopup() local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame TextEntry:Dock( TOP ) TextEntry.OnEnter = function( self ) chat.AddText( self:GetValue() ) -- print the textentry text as a chat message end local TextEntryPH = vgui.Create( "DTextEntry", frame ) TextEntryPH:Dock( TOP ) TextEntryPH:DockMargin( 0, 5, 0, 0 ) TextEntryPH:SetPlaceholderText( "I am a placeholder" ) TextEntryPH.OnEnter = function( self ) chat.AddText( self:GetValue() ) end end )

Undocumented Methods