Skip to content

TextBox

Konoplev Anatolii edited this page Jan 6, 2021 · 11 revisions

TextBox

ClForms.Elements.TextBox
Represents a Windows text box control

public class TextBox: BaseFocusableControl, IElementStyle<TextBox>, ICursorAdmit

Inheritance Control -> BaseFocusableControl -> TextBox
Derived IElementStyle<TextBox>, ICursorAdmit

Examples

The following code example creates the TextBox controls.

var tb1 = new TextBox()
{
    CharacterCasing = CharacterCasing.Lower,
    Text = "Character casing is Lower",
    Tag = "CharacterCasing is modifies the …",
};
tb1.OnEnter += ShowDescriptionByControlEnter;
grid.AddContent(tb1, col: 0, row: 1);var tb4 = new TextBox()
{
    PasswordChar = '●',
    Text = "Password char was set",
    Tag = "PasswordChar has character used to …",
};
tb4.OnTextChanged += TextChanged;
grid.AddContent(tb4, col: 0, row: 4);private void ShowDescriptionByControlEnter(object sender, EventArgs e)
{
    if (sender is TextBox textBox)
    {
        descriptionCodeLabel.Text = textBox.Tag?.ToString();
    }
}private void TextChanged(object sender, PropertyChangedEventArgs<string> e)
{
    if (sender is TextBox textBox)
    {
        textBox.Tag = $"PasswordChar has character … text is: '{e.NewValue}'";
        ShowDescriptionByControlEnter(sender, EventArgs.Empty);
    }
}

You can find more examples of using the TextBox in this project

Remarks

With the TextBox control, the user can enter text in an application. Typically, a TextBox control is used to display, or accept as input, a single line of text.

You can limit the amount of text entered into a TextBox control by setting the MaxLength property to a specific number of characters. TextBox controls can also be used to accept passwords and other sensitive information. You can use the PasswordChar property to mask characters entered in a single-line version of the control. Use the CharacterCasing property to enable the user to type only uppercase, only lowercase, or a combination of uppercase and lowercase characters into the TextBox control.

Constructors

Syntax Description
TextBox() Initialize a new instance TextBox

Properties

Name Type Description
AutoSize bool Gets or sets a value indicating whether the control is resized in accordance with its contents
Background Color Gets or sets a brush that describes the background of a control
BackgroundIsTransparent bool Gets a value indicating whether the Background has Color.NotSet
Bounds Rect Gets the size and location of the control including its nonclient elements, in points, relative to the parent control
CharacterCasing CharacterCasing Gets or sets whether the TextBox control modifies the case of characters as they are typed
DesiredSize Size Gets the size that this element computed during the measure pass of the layout process
DisabledBackground Color Gets or sets a value to display of background when the control is disabled
DisabledForeground Color Gets or sets a value to display of text color when the control is disabled
DrawingContext IDrawingContext Gets a value of the drawing context
FocusBackground Color Focused component background color
FocusForeground Color Focused component text color
Foreground Color Gets or sets a brush that describes the text of a control
ForegroundIsTransparent bool Gets a value indicating whether the Foreground has Color.NotSet
Height int? Gets or sets the height of the control
Id long Gets a value of the control's identifier
IsDisabled bool Gets or sets a value indicating whether the control cannot respond to user interaction
IsFocus bool Gets or sets focus value of component
IsMeasureValid bool Gets a value indicating whether component sizing was performed
IsVisualValid bool Gets a value indicating whether the component is being re-rendered
Location Point Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container
Margin Thickness Gets or sets the outer margin of an element
MaxLength int Gets or sets the maximum number of characters that can be manually entered into the text box
Padding Thickness Gets or sets a Thickness value that describes the amount of space between a control and its child element
Parent ContentControl Gets or sets the parent container of the control
PasswordChar char Gets or sets the character used to mask characters of a password in the control
ReadOnly bool Gets or sets a value indicating whether the contents of the TextBox control can be changed
TabIndex int Gets or sets the sequence for moving the TAB key between the controls inside the container
TabStop bool Gets or sets a value indicating whether the user can focus on the given control using the TAB key
Tag object Gets or sets the object that contains data about the control
Text string Gets or sets the text associated with this control
Width int? Gets or sets the width of the control

Methods

Syntax Description
Arrange(Rect) Positions child elements and determines a size for a Control. Parent elements call this method from their Arrange(Rect) implementation to form a recursive layout update
CanFocus() Indicates whether component focus can be set
Clear() Clears all the content from the text box
InputAction(ConsoleKeyInfo) Handles a keystroke
InvalidateMeasure() Invalidates the measurement state (layout) for the element
InvalidateMeasureIfAutoSize() Invalidates the measurement state (layout) for the element if AutoSize property is true otherwise invalidates the rendering of the element
InvalidateVisual() Invalidates the rendering of the element, and forces a complete new layout pass. OnRender(IDrawingContext) is called after the layout cycle is completed
Measure(Size) Updates DesiredSize of a Control. Parent elements call this method from their own Measure(Size) implementations to form a recursive layout update
OnRender(IDrawingContext) Filling a pseudographics drawing context
ParentWindow() Gets the form the control is in
SetFocus() Sets input focus to current item
SetStyle(Action) Defines actions with an element style

Events

Event Description
OnAutoSizeChanged Occurs when the value of the AutoSize property changes
OnBackgroundChanged Occurs when the value of the Background property changes
OnCharPress Raises the CharPress event
OnCharacterCasingChanged Occurs when the value of the CharacterCasing property changes
OnClick Occurs when the ButtonBase control is clicked
OnDisabledBackgroundChanged Occurs when the value of the DisabledBackground property changes
OnDisabledChanged Occurs when the value of the IsDisabled property changes
OnDisabledForegroundChanged Occurs when the value of the DisabledForeground property changes
OnEnter Input focus event
OnFocusBackgroundChanged Occurs when the value of the FocusBackground property changes
OnFocusChanged Occurs when the value of the IsFocus property changes
OnFocusForegroundChanged Occurs when the value of the FocusForeground property changes
OnForegroundChanged Occurs when the value of the Foreground property changes
OnHeightChanged Occurs when the value of the Height property changes
OnLeave Input focus loss event
OnMarginChanged Occurs when the value of the Margin property changes
OnMaxLengthChanged Occurs when the value of the MaxLength property changes
OnPaddingChanged Occurs when the value of the Padding property changes
OnParentChanged Occurs when the value of the Parent property changes
OnPasswordCharChanged Occurs when the value of the PasswordChar property changes
OnReadOnlyChanged Occurs when the value of the ReadOnly property changes
OnTabIndexChanged Occurs when a property value of TabIndex changes
OnTabStopChanged Occurs when a property value of TabStop changes
OnTagChanged Occurs when the value of the Tag property changes
OnTextChanged Occurs when the value of the Text property changes
OnWidthChanged Occurs when the value of the Width property changes

Clone this wiki locally