BeepTextBox
High-performance text input control with theme integration, search mode, and validation pipeline
Table of Contents
Overview
BeepTextBox is the Beep framework's replacement for System.Windows.Forms.TextBox. Built on BaseControl, it provides custom selection rendering, a theming pipeline, search mode, image suffix support, and a data-binding-friendly value API.
Organized across 10 partial class files: Core, Properties, Events, Input, Methods, Drawing, Effects, Search, Theme, and the main entry file.
Namespace: TheTechIdea.Beep.Winform.Controls | Assembly: TheTechIdea.Beep.Winform.Controls.dll
Inheritance: Component → Control → BaseControl → BeepTextBox | Implements: IBeepTextBox
Key Features
- Theme-aware rendering — Automatically picks up text colors, background, borders, selection highlight, corner radii, and fonts from 27+ design systems
- Custom selection rendering —
SelectionBackColordriven by theme tokens;HideSelectioncontrols focus-aware visibility - Search mode — Toggleable
IsSearchModewith search icon, placeholder, and escape-to-clear - Image suffix — Built-in
BeepImagecomponent for search/clear/custom icons - Validation pipeline —
CausesValidationflag +ValidateData(out message)override hook - Data binding —
SetValue,GetValue,ClearValue, andModifieddirty tracking - Visual effects — Focus borders, hover highlights, shadow effects via theme tokens
Properties
| Property | Type | Default | Description |
|---|---|---|---|
Text | string | "" | Current text content (inherited). |
PlaceholderText | string | "" | Displayed when the control is empty and unfocused. |
SelectedText | string | "" | Read-only. Returns the currently selected text. |
SelectionBackColor | Color | Theme highlight | Background color for selected text. Defaults to TextBoxThemeHelpers.ThemeAwareHighlight(). |
HideSelection | bool | true | When true, hides the selection when the control loses focus. |
Modified | bool | false | Dirty flag tracking whether text changed since last load/save. |
CausesValidation | bool | true | Triggers validation events on focus loss. |
IsSearchMode | bool | false | Enables search behavior: icon, clear button, escape-to-clear. |
DisableMaterialConstraints | bool | false | Disables Material Design sizing constraints. |
BeepImage | BeepImage | null | Optional suffix image (search icon, clear button, etc.). |
ReadOnly | bool | false | Makes the control read-only. |
Multiline | bool | false | Enables multi-line text editing. |
PasswordChar | char | '\0' | Character used to mask password input. |
Methods
| Method | Signature | Description |
|---|---|---|
GetDisplayText | string GetDisplayText() | Returns the text shown to the user (including placeholder formatting). |
GetPreferredSize | Size GetPreferredSize(Size proposed) | Calculates optimal size based on text, font, and theme padding. |
ValidateData | bool ValidateData(out string message) | Validates current text. Override for custom rules. Returns true if valid, false with error message. |
SetValue | void SetValue(object value) | Sets text from a data-bound source. Clears Modified. |
GetValue | object GetValue() | Returns current text for data binding consumption. |
ClearValue | void ClearValue() | Clears text and resets Modified to false. |
Events
| Event | Description |
|---|---|
TextChanged | Raised when the Text property value changes. |
KeyDown / KeyPress / KeyUp | Standard keyboard events. |
Enter | Raised when the control receives focus. |
Leave | Raised when the control loses focus. Triggers validation if CausesValidation is true. |
Search Mode
Setting IsSearchMode = true transforms the text box into a search input:
- A search icon (magnifying glass) renders inside the control
- A clear button appears when text is present
- Escape key clears the search text
- Focus ring and border accent use theme accent tokens
var search = new BeepTextBox { IsSearchMode = true, PlaceholderText = "Search..." };
search.TextChanged += (s, e) => FilterData(search.Text);
Validation
Override ValidateData to implement custom rules:
public class EmailTextBox : BeepTextBox
{
public override bool ValidateData(out string message)
{
if (string.IsNullOrWhiteSpace(Text))
{ message = "Email is required."; return false; }
if (!Text.Contains("@"))
{ message = "Please enter a valid email."; return false; }
message = null; return true;
}
}
Theming
BeepTextBox adapts to the active Beep theme system. The theme controls: text/background/border colors, selection highlight (SelectionBackColor), placeholder color, focus accent color/thickness, border radius (CornerRadius), and font properties.
BeepThemesManager.ApplyTheme("MaterialDark"); // All BeepTextBox instances update automatically
Examples
Data-Bound Input
var box = new BeepTextBox();
box.DataBindings.Add(new Binding("Text", customer, "Name"));
Search with Filter
var search = new BeepTextBox { IsSearchMode = true, PlaceholderText = "Filter..." };
search.TextChanged += (s, e) => grid.Filter(search.Text);
Password Input
var pwd = new BeepTextBox { PasswordChar = '*', MaxLength = 32, PlaceholderText = "Password" };
Architecture
| File | Responsibility |
|---|---|
BeepTextBox.cs | Main entry, class declaration |
BeepTextBox.Core.cs | Constructor, initialization, internal fields |
BeepTextBox.Properties.cs | All public properties |
BeepTextBox.Events.cs | Focus/leave processing, validation triggers |
BeepTextBox.Input.cs | Keyboard input, text operations |
BeepTextBox.Methods.cs | GetDisplayText, ValidateData, SetValue, etc. |
BeepTextBox.Drawing.cs | Custom painting for text, caret, selection |
BeepTextBox.Effects.cs | Focus borders, hover states, shadows |
BeepTextBox.Search.cs | Search mode logic |
BeepTextBox.Theme.cs | Theme application, color resolution |