ClassRadTextBoxControl
Represents a text box control that enables users to enter and edit text with support for multiline editing, auto-completion, and advanced text manipulation features. This control serves as a wrapper around RadTextBoxControlElement and provides comprehensive text input functionality including password masking, scrolling, and data binding capabilities.
Definition
Namespace:Telerik.WinControls.UI
Assembly:Telerik.WinControls.UI.dll
Syntax:
[TelerikToolboxCategory("Editors")]
[DefaultBindingProperty("Text")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class RadTextBoxControl : RadControl, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable, INotifyPropertyChanged, ISupportInitializeNotification, ISupportInitialize, IComponentTreeHandler, ILayoutHandler, IAnalyticsProvider
Inheritance: objectMarshalByRefObjectComponentControlScrollableControlRadControlRadTextBoxControl
Derived Classes:
Implements:
Inherited Members
Constructors
RadTextBoxControl()
Initializes a new instance of the RadTextBoxControl class. Sets up the control styles and registers the initialization event handler for deferred property setting.
Declaration
public RadTextBoxControl()
Properties
AcceptsReturn
Gets or sets a value indicating whether pressing ENTER creates a new line instead of activating the default button. When true in a multiline text box, ENTER keypresses create new lines; when false, they activate the form's default button.
AcceptsTab
Gets or sets a value indicating whether pressing the TAB key inserts a tab character instead of moving focus. When true in a multiline text box, TAB keypresses insert tab characters; when false, they move focus to the next control.
AutoCompleteDataSource
Gets or sets the data source that provides auto-complete suggestions. This property specifies the collection or data source used to populate auto-complete items for text suggestions.
Declaration
[Browsable(true)]
public object AutoCompleteDataSource { get; set; }
Property Value
AutoCompleteDisplayMember
Gets or sets the property name to use as the display member for auto-complete items. This property determines which field from the AutoCompleteDataSource is displayed as suggestion text.
Declaration
[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[Browsable(true)]
public string AutoCompleteDisplayMember { get; set; }
Property Value
AutoCompleteItems
Gets the collection of auto-complete items used for text suggestions. This property provides direct access to the items collection for adding, removing, or modifying suggestion entries.
Declaration
[Browsable(true)]
public RadListDataItemCollection AutoCompleteItems { get; }
Property Value
AutoCompleteMode
Gets or sets the auto-completion mode that controls how automatic text completion works. This property determines whether suggestions are displayed in a dropdown, appended to the text, or both.
Declaration
public virtual AutoCompleteMode AutoCompleteMode { get; set; }
Property Value
AutoSize
Gets or sets a value indicating whether the control automatically resizes its height to display all content. For RadTextBoxControl, AutoSize affects only the height dimension and adjusts based on font size and content.
Declaration
[Browsable(true)]
public override bool AutoSize { get; set; }
Property Value
Overrides
CaretIndex
Gets or sets the position of the text cursor (caret) within the text. This property represents the zero-based index of the character position where text insertion occurs.
Declaration
[Browsable(false)]
public int CaretIndex { get; set; }
Property Value
CharacterCasing
Gets or sets how the case of typed characters is modified automatically. This property allows forcing text to uppercase, lowercase, or preserving the original case as typed.
Declaration
public CharacterCasing CharacterCasing { get; set; }
Property Value
DefaultSize
Gets the default size of the text box control.
DropDownMaxSize
Gets or sets the maximum size of the auto-complete dropdown list. This property controls the largest allowable dimensions for the dropdown that displays auto-complete suggestions.
Declaration
[Browsable(false)]
public Size DropDownMaxSize { get; set; }
Property Value
DropDownMinSize
Gets or sets the minimum size of the auto-complete dropdown list. This property controls the smallest allowable dimensions for the dropdown that displays auto-complete suggestions.
Declaration
[Browsable(false)]
public Size DropDownMinSize { get; set; }
Property Value
EmbeddedLabelText
Gets or sets the text displayed in the embedded label. This property controls the content of the label that appears when ShowEmbeddedLabel is enabled.
HideSelection
Gets or sets a value indicating whether selected text remains highlighted when the control loses focus. When true, selected text highlighting is hidden when focus moves away from the control; when false, selection remains visible.
HorizontalScrollBarState
Gets or sets when the horizontal scroll bar should appear in a multiline text box. This property controls the visibility behavior of the horizontal scrollbar based on content overflow.
Declaration
public ScrollState HorizontalScrollBarState { get; set; }
Property Value
IsReadOnly
Gets or sets a value indicating whether the text box is in read-only mode, preventing user text modification. When true, users can select and copy text but cannot edit the content; when false, full editing is allowed.
IsReadOnlyCaretVisible
Gets or sets a value indicating whether the text cursor is visible when the control is in read-only mode. When true, the caret remains visible in read-only mode; when false, no cursor is shown.
Lines
Gets or sets the lines of text in the text box as an array of strings. Each array element represents a separate line, allowing programmatic access to multiline text content.
ListElement
Gets the auto-complete list element that displays suggestion items. This property provides access to the dropdown list that shows auto-complete suggestions to the user.
Declaration
[Browsable(false)]
public RadTextBoxListElement ListElement { get; }
Property Value
MaxDropDownItemCount
Gets or sets the maximum number of visible items in the auto-complete dropdown list. This property determines how many suggestion items are displayed simultaneously before scrolling is required.
MaxLength
Gets or sets the maximum number of characters that can be entered or pasted into the text box. When set to a value other than MaxValue, input is limited to this character count.
Multiline
Gets or sets a value indicating whether the text box supports multiple lines of text. When true, the control can display and accept multiple lines with line breaks; when false, only single-line text is supported.
NullText
Gets or sets the placeholder text displayed when the text box is empty and does not have focus. This text provides users with hints about the expected input format or content.
NullTextColor
Gets or sets the color of the placeholder text displayed when the text box is empty. This property controls the visual appearance of the NullText when shown to users.
Declaration
[Browsable(false)]
public Color NullTextColor { get; set; }
Property Value
PasswordChar
Gets or sets the character used to mask password characters in single-line text entry. When set to a non-null character, all typed characters will be displayed as this masking character for secure password input.
RadContextMenu
Gets or sets the context menu associated with this text box control. This property provides access to the right-click menu that appears when users right-click on the text box.
Declaration
public virtual RadContextMenu RadContextMenu { get; set; }
Property Value
A RadContextMenu that represents the shortcut menu associated with the control.
SelectedText
Gets or sets the currently selected text within the text box control. This property allows reading the selected text or replacing the selection with new text content.
Declaration
[Browsable(false)]
public string SelectedText { get; set; }
Property Value
SelectionColor
Gets or sets the background color used for selected text within the text box. This property controls the highlight color that appears behind selected text characters.
Declaration
[Browsable(false)]
public Color SelectionColor { get; set; }
Property Value
SelectionLength
Gets or sets the number of characters in the current text selection. This property determines how many characters from the SelectionStart position are selected.
Declaration
[Browsable(false)]
public int SelectionLength { get; set; }
Property Value
SelectionOpacity
Gets or sets the opacity level of the text selection highlighting. This property controls the transparency of the selection background color, with values from 0 (fully transparent) to 100 (fully opaque).
SelectionStart
Gets or sets the starting position of the text selection within the text box. This property represents the zero-based index where the text selection begins.
Declaration
[Browsable(false)]
public int SelectionStart { get; set; }
Property Value
ShowClearButton
Gets or sets a value indicating whether the clear button is displayed within the text box. When enabled, users can click the clear button to quickly remove all text from the control.
ShowEmbeddedLabel
Gets or sets a value indicating whether the embedded label is displayed within the text box. When enabled, the embedded label provides descriptive text that appears alongside the input area. It is recommended to set AutoSize to true when using the embedded label.
ShowNullText
Gets or sets a value indicating whether the placeholder text remains visible when the control has focus and the text is empty. When true, NullText is displayed even when the control is focused; when false, it disappears on focus.
Text
Gets or sets the text content displayed in the text box control. This property contains the actual text that users can view and edit within the control.
Declaration
[Bindable(true)]
public override string Text { get; set; }
Property Value
Overrides
TextAlign
Gets or sets the horizontal alignment of text within the text box control. This property determines whether text is aligned to the left, center, or right within the control's bounds.
Declaration
public HorizontalAlignment TextAlign { get; set; }
Property Value
TextBoxElement
Gets the associated text box element that provides the core text editing functionality. This property provides access to the underlying RadTextBoxControlElement for advanced customization scenarios.
Declaration
[Browsable(false)]
public RadTextBoxControlElement TextBoxElement { get; }
Property Value
TextLength
Gets the total length of text currently contained in the text box. This property returns the number of characters in the Text property.
UseSystemPasswordChar
Gets or sets a value indicating whether the text should be displayed using the system's default password character. When enabled, all characters in the text box are masked with the system password character for secure input.
Declaration
public virtual bool UseSystemPasswordChar { get; set; }
Property Value
VerticalScrollBarState
Gets or sets when the vertical scroll bar should appear in a multiline text box. This property controls the visibility behavior of the vertical scrollbar based on content overflow.
Declaration
public ScrollState VerticalScrollBarState { get; set; }
Property Value
WordWrap
Gets or sets a value indicating whether text automatically wraps to the next line when it reaches the control's edge. When true in a multiline text box, long lines are broken at word boundaries; when false, horizontal scrolling is used instead.
Methods
AppendText(string)
Appends the specified text to the end of the current text content in the text box. This method adds new text without replacing existing content.
Declaration
public void AppendText(string text)
Parameters
text
The text to append to the existing content.
Clear()
Removes all text content from the text box, making it empty. This method clears the entire Text property and resets the cursor position.
Declaration
public void Clear()
Copy()
Copies the currently selected text to the clipboard without removing it from the text box. The selected text remains in the control and is available for pasting elsewhere.
Declaration
public bool Copy()
Returns
true if the copy operation was successful; otherwise, false.
CreateAccessibilityInstance()
Creates an accessibility object for this text box control to support assistive technologies. When EnableRadAccessibilityObjects is enabled, returns a custom accessibility object; otherwise, returns the base implementation.
Declaration
protected override AccessibleObject CreateAccessibilityInstance()
Returns
An AccessibleObject that provides accessibility support for this control.
Overrides
CreateChildItems(RadElement)
Creates the child elements of the control by instantiating and configuring the internal RadTextBoxControlElement. This method sets up the text box element and establishes event handlers for text change notifications.
Declaration
protected override void CreateChildItems(RadElement parent)
Parameters
parent
The parent RadElement that will contain the child elements.
Overrides
CreateTextBoxElement()
Creates the associated text box element that provides the core text editing functionality. This method can be overridden in derived classes to provide custom text box element implementations.
Declaration
protected virtual RadTextBoxControlElement CreateTextBoxElement()
Returns
A new instance of RadTextBoxControlElement or a derived class.
Cut()
Cuts the currently selected text to the clipboard, removing it from the text box. This operation combines copying the selection and deleting it from the control.
Declaration
public bool Cut()
Returns
true if the cut operation was successful; otherwise, false.
Delete()
Deletes the character at the current cursor position. This method removes one character from the text content at the caret location.
Declaration
public bool Delete()
Returns
true if the delete operation was successful; otherwise, false.
Delete(bool)
Deletes a character at the current cursor position with directional control. This method can delete either the character before (backspace) or after (delete) the cursor.
Delete(bool, bool)
Deletes text with advanced control over direction and word boundary behavior. When Control is pressed, deletion extends to word boundaries for faster text editing.
Declaration
public bool Delete(bool nextCharacter, bool isControlPressed)
Parameters
nextCharacter
true to delete the character or word after the cursor; false to delete before the cursor.
isControlPressed
true to delete to the end of the word; false to delete only a single character.
Returns
true if the delete operation was successful; otherwise, false.
DeselectAll()
Clears the current text selection by setting the SelectionLength to zero. After calling this method, no characters will be selected in the text box.
Declaration
public bool DeselectAll()
Returns
true if the selection was successfully cleared; otherwise, false.
Insert(string)
Inserts the specified text at the current cursor position or replaces the selected text. If text is selected, it will be replaced; otherwise, the text is inserted at the caret position.
OnGotFocus(EventArgs)
Handles the GotFocus event by transferring focus to the internal text box element and animating the embedded label. This method ensures proper focus management and visual feedback when the control receives focus.
OnKeyPress(KeyPressEventArgs)
Handles key press events by delegating to the base implementation and internal behavior processing. This method processes character input for the text box control.
Declaration
protected override void OnKeyPress(KeyPressEventArgs e)
Parameters
e
A KeyPressEventArgs containing the event data.
Overrides
OnLoad(Size)
Handles the load event by setting up the embedded label position based on the desired size. This method ensures proper layout initialization when the control is loaded.
Declaration
protected override void OnLoad(Size desiredSize)
Parameters
desiredSize
The desired size for the control layout.
Overrides
OnLostFocus(EventArgs)
Handles the LostFocus event by removing focus from the internal text box element and animating the embedded label. This method ensures proper focus cleanup and visual feedback when the control loses focus.
OnTextChanging(TextChangingEventArgs)
Raises the TextChanging event when text is about to change. This method provides an opportunity for derived classes to handle text changes before they occur.
Declaration
protected virtual void OnTextChanging(TextChangingEventArgs e)
Parameters
e
The TextChangingEventArgs instance containing the event data.
Paste()
Replaces the currently selected text with the contents of the clipboard. If no text is selected, the clipboard content is inserted at the current cursor position.
Declaration
public bool Paste()
Returns
true if the paste operation was successful; otherwise, false.
ProcessAutoSizeChanged(bool)
Processes changes to the AutoSize property and adjusts the control's stretch behavior. When AutoSize is disabled, the control can stretch vertically; when enabled, it maintains fixed height based on content.
Declaration
protected override void ProcessAutoSizeChanged(bool value)
Parameters
value
The new value of the AutoSize property.
Overrides
ProcessDialogChar(char)
Processes dialog characters for the text box control, handling special key combinations. This method manages Alt and Control key combinations while allowing normal character processing for text input.
ProcessMnemonic(char)
Processes mnemonic characters for accessibility support. This method handles mnemonic key combinations but returns false as text boxes typically don't support mnemonics.
ResetBackColorThemeOverrides()
Resets theme overrides for the BackColor property on the text box element and its child elements. This method removes custom background color theming and restores default theme values.
Declaration
protected override void ResetBackColorThemeOverrides()
Overrides
ResetForeColorThemeOverrides()
Resets theme overrides for the ForeColor property on the text box element. This method removes custom foreground color theming and restores default theme values.
Declaration
protected override void ResetForeColorThemeOverrides()
Overrides
ScrollToCaret()
Scrolls the text box content to ensure the current caret position is visible. This method brings the cursor into view when it might be outside the visible area.
Declaration
public void ScrollToCaret()
Select(int, int)
Selects a range of text within the text box starting at the specified position. This method sets both the SelectionStart and SelectionLength properties.
SelectAll()
Selects all text content in the text box. This method sets the selection to include the entire Text property content.
Declaration
public void SelectAll()
SetBackColorThemeOverrides()
Sets theme overrides for the BackColor property on the text box element and its child elements. This method applies the control's background color to all visual states of the internal text box components.
Declaration
protected override void SetBackColorThemeOverrides()
Overrides
SetForeColorThemeOverrides()
Sets theme overrides for the ForeColor property on the text box element. This method applies the control's foreground color to all visual states of the internal text box component.
Declaration
protected override void SetForeColorThemeOverrides()
Overrides
Events
ContextMenuOpening
Occurs when the context menu is about to be displayed, allowing customization of menu items. This event provides an opportunity to modify or replace the context menu before it appears to the user.
Declaration
public event TreeBoxContextMenuOpeningEventHandler ContextMenuOpening
Event Value
CreateTextBlock
Occurs when a new text block instance is being created. This event allows customization of ITextBlock creation for advanced text rendering scenarios.
Declaration
public event CreateTextBlockEventHandler CreateTextBlock
Event Value
IMECompositionEnded
Occurs when the Input Method Editor (IME) completes text composition for international text input. This event is fired when users finish entering text using an IME and the composition process is complete.
Declaration
public event EventHandler IMECompositionEnded
Event Value
IMECompositionResult
Occurs when the Input Method Editor (IME) produces composition results during text input. This event is fired when IME has intermediate or final results ready, which may occur before composition ends for languages like Korean.
Declaration
public event EventHandler<IMECompositionResultEventArgs> IMECompositionResult
Event Value
EventHandler<IMECompositionResultEventArgs>
IMECompositionStarted
Occurs when the Input Method Editor (IME) starts text composition for international text input. This event is fired when users begin entering text using an IME for languages such as Chinese, Japanese, or Korean.
Declaration
public event EventHandler IMECompositionStarted
Event Value
SelectionChanged
Occurs after the text selection has changed. This event is raised whenever the user or code changes the selected text range within the control.
Declaration
public event SelectionChangedEventHandler SelectionChanged
Event Value
SelectionChanging
Occurs when the text selection is about to change, allowing the change to be canceled. This event provides an opportunity to prevent selection changes by setting the Cancel property in the event arguments.
Declaration
public event SelectionChangingEventHandler SelectionChanging
Event Value
TextBlockFormatting
Occurs when text blocks are being formatted, allowing custom styling of text portions. This event provides access to individual text blocks for applying custom formatting such as fonts, colors, or styles.
Declaration
public event TextBlockFormattingEventHandler TextBlockFormatting
Event Value
TextChanging
Occurs when the text content is about to change, providing an opportunity to cancel the change. This event allows validation or modification of text before it is applied to the control.
Declaration
public event TextChangingEventHandler TextChanging
Event Value