Name

TextBoxBase

Synopsis

This is the base class for the TextBox and RichTextBox classes. It provides the base functionality for a Control into which the user can type and edit text.

You can set the Text in the control, or AppendText(). You can also find the TextLength. You can Select() text, or manipulate the SelectionStart and SelectionLength. A SelectedText property allows you to retrieve the current selection. If the SelectionLength is 0, the SelectionStart represents the current position of the caret. You can ensure that the caret is visible using ScrollToCaret( ). SelectAll() will select the entire content, and Clear() will remove it.

You can Cut( ) or Copy() the selection to the clipboard, and Paste() an IDataObject from the clipboard or a drag-and-drop operation.

The textbox is single line by default, but you can enable Multiline support (and find the number of Lines in the control). If you have a multiline control, you can enable WordWrap.

There is basic Undo() support. You can find out if the control CanUndo the previous operation, and you can use ClearUndo() to clear the undo buffer.


public abstract class TextBoxBase : Control {

// Public Instance Properties

   public bool AcceptsTab{set; get; }

   public virtual bool AutoSize{set; get; }

   public override Color BackColor{set; get; }

// overrides Control

   public override Image BackgroundImage{set; get; }

// overrides Control

   public BorderStyle BorderStyle{set; get; }

   public bool CanUndo{get; }

   public override Color ForeColor{set; get; ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.