Click or drag to resize
DigitalRuneTextBox Class
Represents a control that can be used to display or edit unformatted text.
Inheritance Hierarchy

Namespace: DigitalRune.Game.UI.Controls
Assembly: DigitalRune.Game.UI (in DigitalRune.Game.UI.dll) Version: 1.8.0.0 (1.8.0.14553)
Syntax
public class TextBox : UIControl

The TextBox type exposes the following members.

Constructors
  NameDescription
Public methodTextBox
Initializes a new instance of the TextBox class.
Top
Methods
  NameDescription
Public methodArrange
Positions child elements and determines a size for a control.
(Inherited from UIControl.)
Public methodBringIntoView
Attempts to bring this element into view, within any scrollable regions it is contained within.
(Inherited from UIControl.)
Public methodClearSelection
Clears the text selection.
Public methodCopy
Copies the current selection from the text box to the clipboard.
Public methodCut
Removes the current selection from the text box and copies it to the clipboard.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFocus
Moves the input focus to this control.
(Inherited from UIControl.)
Public methodGetControl
Gets a control by name from the visual subtree of this control.
(Inherited from UIControl.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValueT(Int32)
Gets the value of the property with the given ID.
(Inherited from GameObject.)
Public methodGetValueT(String)
Gets the value of the property with the given name.
(Inherited from GameObject.)
Public methodGetValueT(GamePropertyMetadataT)
Gets the value of the property with the given metadata.
(Inherited from GameObject.)
Protected methodHitTest
Tests if a position is over a control.
(Inherited from UIControl.)
Public methodInvalidateArrange
Invalidates the arrange state (layout) for the control.
(Inherited from UIControl.)
Public methodInvalidateMeasure
Invalidates the measurement state (layout) for the control.
(Inherited from UIControl.)
Public methodInvalidateVisual
Invalidates the cached RenderData.
(Inherited from UIControl.)
Public methodLoad
Loads the content of the game object.
(Inherited from GameObject.)
Public methodMeasure
Updates the DesiredWidth and DesiredHeight of the control.
(Inherited from UIControl.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodNewFrame
Tells the game object to prepare itself for the next time step.
(Inherited from GameObject.)
Protected methodOnArrange
Called by Arrange(Vector2F, Vector2F) to arrange the visual children.
(Overrides UIControlOnArrange(Vector2F, Vector2F).)
Protected methodOnHandleInput
Called when the control should handle device input.
(Overrides UIControlOnHandleInput(InputContext).)
Protected methodOnLoad
Called when the game object should load its content.
(Overrides UIControlOnLoad.)
Protected methodOnMeasure
Called by Measure(Vector2F) to compute the control-specific desired size.
(Overrides UIControlOnMeasure(Vector2F).)
Protected methodOnPropertyChanged(PropertyChangedEventArgs)
Raises the PropertyChanged event.
(Inherited from GameObject.)
Protected methodOnPropertyChangedT(GamePropertyT, T, T)
Is called after a game object property was changed.
(Inherited from GameObject.)
Protected methodOnPropertyChangedT(GamePropertyT, T, T)
Is called after a game object property was changed.
(Inherited from UIControl.)
Protected methodOnRender
Called when the control and its visual children should be rendered.
(Inherited from UIControl.)
Protected methodOnTemplateChanged
Raises the TemplateChanged event.
(Inherited from GameObject.)
Protected methodOnUnload
Called when the game object should unload its content.
(Overrides UIControlOnUnload.)
Protected methodOnUpdate
Called when the game object should be updated.
(Inherited from UIControl.)
Public methodPaste
Pastes the contents of the clipboard into the text box.
Public methodRender
Renders the control (including visual children).
(Inherited from UIControl.)
Public methodSelect
Selects a range of text in the text box.
Public methodSelectAll
Selects all contents of the text box.
Public methodSetValueT(Int32, T)
Sets the value of the property with the given ID.
(Inherited from GameObject.)
Public methodSetValueT(String, T)
Sets the value of the property with the given name.
(Inherited from GameObject.)
Public methodSetValueT(GamePropertyMetadataT, T)
Set the value of the property for the given metadata.
(Inherited from GameObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUnload
Unloads the content of the game object.
(Inherited from GameObject.)
Public methodUpdate
Updates this game object.
(Inherited from GameObject.)
Public methodUpdateLayout
Ensures that all visual child controls of this element are properly updated for layout.
(Inherited from UIControl.)
Top
Extension Methods
  NameDescription
Public Extension MethodGetAncestors
Gets the ancestors of the control in the visual tree.
(Defined by UIHelper.)
Public Extension MethodGetDescendantsOverloaded.
Gets the descendants of the control in the visual tree using a depth-first search.
(Defined by UIHelper.)
Public Extension MethodGetDescendants(Boolean)Overloaded.
Gets the descendants of the control in the visual tree using either a depth-first or a breadth-first search.
(Defined by UIHelper.)
Public Extension MethodGetLeaves
Gets the leaves of the control in the visual tree.
(Defined by UIHelper.)
Public Extension MethodGetRoot
Returns the root control of the visual tree.
(Defined by UIHelper.)
Public Extension MethodGetSelfAndAncestors
Gets the control and its ancestors in the visual tree.
(Defined by UIHelper.)
Public Extension MethodGetSubtreeOverloaded.
Gets the subtree (the given control and all of its descendants in the visual tree) using a depth-first search.
(Defined by UIHelper.)
Public Extension MethodGetSubtree(Boolean)Overloaded.
Gets the subtree (the given control and all of its descendants in the visual tree) using either a depth-first or a breadth-first search.
(Defined by UIHelper.)
Top
Fields
  NameDescription
Public fieldStatic memberGuideDescriptionPropertyId
The ID of the GuideDescription game object property.
Public fieldStatic memberGuideTitlePropertyId
The ID of the GuideTitle game object property.
Public fieldStatic memberIsPasswordPropertyId
The ID of the IsPassword game object property.
Public fieldStatic memberIsReadOnlyPropertyId
The ID of the IsReadOnly game object property.
Public fieldStatic memberMaxLengthPropertyId
The ID of the MaxLength game object property.
Public fieldStatic memberMaxLinesPropertyId
The ID of the MaxLines game object property.
Public fieldStatic memberMinLinesPropertyId
The ID of the MinLines game object property.
Public fieldStatic memberPasswordCharacterPropertyId
The ID of the PasswordCharacter game object property.
Public fieldStatic memberSelectionColorPropertyId
The ID of the SelectionColor game object property.
Public fieldStatic memberTextPropertyId
The ID of the Text game object property.
Public fieldStatic memberVerticalScrollBarStylePropertyId
The ID of the VerticalScrollBarStyle game object property.
Public fieldStatic memberVerticalScrollBarVisibilityPropertyId
The ID of the VerticalScrollBarVisibility game object property.
Top
Properties
  NameDescription
Public propertyActualBounds
Gets the actual bounding rectangle of the control (defined by ActualX, ActualY, ActualWidth and ActualHeight).
(Inherited from UIControl.)
Public propertyActualHeight
Gets the actual height of the control (computed in Arrange(Vector2F, Vector2F)).
(Inherited from UIControl.)
Public propertyActualIsEnabled
Gets a value indicating whether this control is actually enabled, taking into account the IsEnabled flag and the state of the VisualParent.
(Inherited from UIControl.)
Public propertyActualIsVisible
Gets a value indicating whether this control is actually visible, taking into account the IsVisible flag and the state of the VisualParent.
(Inherited from UIControl.)
Public propertyActualWidth
Gets the actual width of the control (computed in Arrange(Vector2F, Vector2F)).
(Inherited from UIControl.)
Public propertyActualX
Gets the actual X position of the top left corner of the control's bounds in screen coordinates (computed in Arrange(Vector2F, Vector2F)).
(Inherited from UIControl.)
Public propertyActualY
Gets the actual Y position of the top left corner of the control's bounds in screen coordinates (computed in Arrange(Vector2F, Vector2F)).
(Inherited from UIControl.)
Public propertyAllowedPlayer
Gets or sets the LogicalPlayerIndex from which input is accepted.
(Inherited from UIControl.)
Public propertyAutoUnfocus
Gets or sets a value indicating whether this control clears the focus when the mouse clicks another control than the currently focused control. This is a game object property.
(Inherited from UIControl.)
Public propertyBackground
Gets or sets the background color. This is a game object property.
(Inherited from UIControl.)
Public propertyCaretIndex
Gets or sets the position of the caret.
Public propertyContextMenu
Gets or sets the context menu that should pop up when the control is right-clicked (tap-and-hold on Windows Phone 7).
(Inherited from UIControl.)
Public propertyCursor
Gets or sets the mouse cursor that should be displayed when the mouse is over this control.
(Inherited from UIControl.)
Public propertyDesiredHeight
Gets the desired height (including Margin) (which is computed in Measure(Vector2F)).
(Inherited from UIControl.)
Public propertyDesiredWidth
Gets the desired width (including Margin) (which is computed in Measure(Vector2F)).
(Inherited from UIControl.)
Public propertyEvents
Gets the game object events.
(Inherited from GameObject.)
Public propertyFocusable
Gets or sets a value indicating whether this UIControl can receive the input focus. This is a game object property.
(Inherited from UIControl.)
Public propertyFocusWhenMouseOver
Gets or sets a value indicating whether the control automatically receives focus when the mouse is over the control (without being clicked). This is a game object property.
(Inherited from UIControl.)
Public propertyFont
Gets or sets the font that is used if the control renders text. This is a game object property.
(Inherited from UIControl.)
Public propertyForeground
Gets or sets the foreground color. This is a game object property.
(Inherited from UIControl.)
Public propertyGuideDescription
Gets or sets the description that is displayed with the software keyboard. This is a game object property.
Public propertyGuideTitle
Gets or sets the title that is displayed with the software keyboard. This is a game object property.
Public propertyHasRenderTransform
Gets a value indicating whether this control has a render transform that is not the identity transformation.
(Inherited from UIControl.)
Public propertyHeight
Gets or sets the user-defined height. This is a game object property.
(Inherited from UIControl.)
Public propertyHorizontalAlignment
Gets or sets the horizontal alignment of this control. This is a game object property.
(Inherited from UIControl.)
Public propertyInputService
Gets the IInputService.
(Inherited from UIControl.)
Public propertyIsArrangeValid
Gets a value indicating whether the Arrange(Vector2F, Vector2F) results are up-to-date.
(Inherited from UIControl.)
Public propertyIsEnabled
Gets or sets a value indicating whether this control is enabled. This is a game object property.
(Inherited from UIControl.)
Public propertyIsFocused
Gets a value indicating whether this control has the input focus. This is a game object property.
(Inherited from UIControl.)
Public propertyIsFocusScope
Gets or sets a value indicating whether this control is a focus scope. This is a game object property.
(Inherited from UIControl.)
Public propertyIsFocusWithin
Gets (or sets) a value indicating whether the focus is on this control or on any of the visual children.
(Inherited from UIControl.)
Public propertyIsLoaded
Gets a value indicating whether the content of this object was loaded.
(Inherited from GameObject.)
Public propertyIsMeasureValid
Gets a value indicating whether the Measure(Vector2F) results (DesiredWidth and DesiredHeight) are up-to-date.
(Inherited from UIControl.)
Public propertyIsMouseDirectlyOver
Gets a value indicating whether the mouse is over this control and not over a visual child control.
(Inherited from UIControl.)
Public propertyIsMouseOver
Gets or sets a value indicating whether the mouse is over this control or over a visual child. This is a game object property.
(Inherited from UIControl.)
Public propertyIsMultiline
Gets a value indicating whether this text box is a multi-line text box that accepts ENTER keys to create new lines.
Public propertyIsPassword
Gets or sets a value indicating whether this text box is a password box that displays PasswordCharacters instead of the real characters. This is a game object property.
Public propertyIsReadOnly
Gets or sets a value indicating whether this text box is read-only. This is a game object property.
Public propertyIsVisible
Gets or sets a value indicating whether this control is visible. This is a game object property.
(Inherited from UIControl.)
Public propertyIsVisualValid
Gets a value indicating whether the cached RenderData is up-to-date.
(Inherited from UIControl.)
Public propertyMargin
Gets or sets the margin. This is a game object property.
(Inherited from UIControl.)
Public propertyMaxHeight
Gets or sets the maximal height of the control. This is a game object property.
(Inherited from UIControl.)
Public propertyMaxLength
Gets or sets the maximal number of characters in the Text. This is a game object property.
Public propertyMaxLines
Gets or sets the maximal number of visible lines. This is a game object property.
Public propertyMaxWidth
Gets or sets the maximal width of the control. This is a game object property.
(Inherited from UIControl.)
Public propertyMinHeight
Gets or sets the minimal height of the control. This is a game object property.
(Inherited from UIControl.)
Public propertyMinLines
Gets or sets the minimal number of visible lines. This is a game object property.
Public propertyMinWidth
Gets or sets the minimal width of the control. This is a game object property.
(Inherited from UIControl.)
Public propertyName
Gets or sets the name.
(Inherited from GameObject.)
Public propertyOpacity
Gets or sets the opacity. This is a game object property.
(Inherited from UIControl.)
Public propertyPadding
Gets or sets the padding. This is a game object property.
(Inherited from UIControl.)
Public propertyPasswordCharacter
Gets or sets the character that is used instead of normal character if IsPassword is set. This is a game object property.
Public propertyProperties
Gets the game object properties.
(Inherited from GameObject.)
Public propertyRenderData
Gets or sets the cached renderer data.
(Inherited from UIControl.)
Public propertyRendererInfo Obsolete.
Gets or sets the cached renderer data.
(Inherited from UIControl.)
Public propertyRenderRotation
Gets or sets the rotation of the RenderTransform. This is a game object property.
(Inherited from UIControl.)
Public propertyRenderScale
Gets or sets the scale of the RenderTransform. This is a game object property.
(Inherited from UIControl.)
Public propertyRenderTransform
Gets the render transformation.
(Inherited from UIControl.)
Public propertyRenderTransformOrigin
Gets or sets the relative origin of the RenderTransform. This is a game object property.
(Inherited from UIControl.)
Public propertyRenderTranslation
Gets or sets the translation of the RenderTransform. This is a game object property.
(Inherited from UIControl.)
Public propertyScreen
Gets the UIScreen.
(Inherited from UIControl.)
Public propertySelectedText
Gets the content of the current selection in the text box.
Public propertySelectionColor
Gets or sets the background color used for text selections. This is a game object property.
Public propertyStyle
Gets or sets the style.
(Inherited from UIControl.)
Public propertyTag Obsolete.
Gets or sets a user-defined tag.
(Inherited from UIControl.)
Public propertyTemplate
Gets or sets the template.
(Inherited from GameObject.)
Public propertyText
Gets or sets the text. This is a game object property.
Public propertyToolTip
Gets or sets the tool tip. This is a game object property.
(Inherited from UIControl.)
Public propertyUIService
Gets the IUIService.
(Inherited from UIControl.)
Public propertyUserData
Gets or sets user-defined data.
(Inherited from UIControl.)
Public propertyVerticalAlignment
Gets or sets the vertical alignment of this control. This is a game object property.
(Inherited from UIControl.)
Public propertyVerticalScrollBarStyle
Gets or sets the style that is applied to the vertical ScrollBar. This is a game object property.
Public propertyVerticalScrollBarVisibility
Gets or sets the ScrollBarVisibility of the vertical ScrollBar. This is a game object property.
Public propertyVisualCaret
Gets the position of the top left corner of the caret rectangle/line.
Public propertyVisualChildren
Gets the visual children.
(Inherited from UIControl.)
Public propertyVisualClip
Gets the clipping rectangle.
Public propertyVisualOffset
Gets the offset which is the horizontal offset for single-line text boxes or the vertical offset for multi-line text boxes (see also MaxLines and IsMultiline).
Public propertyVisualParent
Gets the visual parent.
(Inherited from UIControl.)
Public propertyVisualSelectionBounds
Gets the bounds of the text selection (for rendering).
Public propertyVisualState
Gets the visual state of the control as string.
(Inherited from UIControl.)
Public propertyVisualText
Gets the text exactly as it should be displayed (wrapping already applied).
Public propertyWidth
Gets or sets the user-defined width. This is a game object property.
(Inherited from UIControl.)
Public propertyX
Gets or sets the x-position offset of the control. (Use this only for controls in a Canvas or under the UIScreen.) This is a game object property.
(Inherited from UIControl.)
Public propertyY
Gets or sets the y-position offset of the control. (Use this only for controls in a Canvas or under the UIScreen.) This is a game object property.
(Inherited from UIControl.)
Top
Events
  NameDescription
Public eventInputProcessed
Occurs after the device input was processed.
(Inherited from UIControl.)
Public eventInputProcessing
Occurs before the device input is processed.
(Inherited from UIControl.)
Public eventPropertyChanged
Occurs when a property value has changed.
(Inherited from GameObject.)
Public eventTemplateChanged
Occurs when the Template changed.
(Inherited from GameObject.)
Top
Explicit Interface Implementations
Remarks
The text box can be a multi-line text box (if MinLines or MaxLines is greater than 1). It supports vertical scrolling but not horizontal scrolling. On Windows, text can be entered using the keyboard. On Windows Phone 7, the software keyboard is opened when the text box is clicked. On Xbox 360, the software keyboard is opened when the text box is focused and A on the gamepad is clicked.
Examples
The following example creates a multi-line text box with a context menu.
C#
// Create a multi-line text box.
var textBox = new TextBox
{
  Margin = new Vector4F(4),
  Text = "Lorem ipsum dolor sit ...",
  MaxLines = 5,   // Show max 5 lines of text.
  HorizontalAlignment = HorizontalAlignment.Stretch,
};

// Add a context menu (Cut, Copy, Paste) to the text box.
var contextMenu = new ContextMenu();
var cut = new MenuItem { Content = new TextBlock { Text = "Cut" } };
var copy = new MenuItem { Content = new TextBlock { Text = "Copy" } };
var paste = new MenuItem { Content = new TextBlock { Text = "Paste" } };
cut.Click += (s, e) => textBox.Cut();
copy.Click += (s, e) => textBox.Copy();
paste.Click += (s, e) => textBox.Paste();
contextMenu.Items.Add(cut);
contextMenu.Items.Add(copy);
contextMenu.Items.Add(paste);
textBox.ContextMenu = contextMenu;

// To show the text box, add it to an existing content control or panel.
panel.Children.Add(textBox);
See Also