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 — SelectionBackColor driven by theme tokens; HideSelection controls focus-aware visibility
  • Search mode — Toggleable IsSearchMode with search icon, placeholder, and escape-to-clear
  • Image suffix — Built-in BeepImage component for search/clear/custom icons
  • Validation pipeline — CausesValidation flag + ValidateData(out message) override hook
  • Data binding — SetValue, GetValue, ClearValue, and Modified dirty tracking
  • Visual effects — Focus borders, hover highlights, shadow effects via theme tokens

Properties

PropertyTypeDefaultDescription
Textstring""Current text content (inherited).
PlaceholderTextstring""Displayed when the control is empty and unfocused.
SelectedTextstring""Read-only. Returns the currently selected text.
SelectionBackColorColorTheme highlightBackground color for selected text. Defaults to TextBoxThemeHelpers.ThemeAwareHighlight().
HideSelectionbooltrueWhen true, hides the selection when the control loses focus.
ModifiedboolfalseDirty flag tracking whether text changed since last load/save.
CausesValidationbooltrueTriggers validation events on focus loss.
IsSearchModeboolfalseEnables search behavior: icon, clear button, escape-to-clear.
DisableMaterialConstraintsboolfalseDisables Material Design sizing constraints.
BeepImageBeepImagenullOptional suffix image (search icon, clear button, etc.).
ReadOnlyboolfalseMakes the control read-only.
MultilineboolfalseEnables multi-line text editing.
PasswordCharchar'\0'Character used to mask password input.

Methods

MethodSignatureDescription
GetDisplayTextstring GetDisplayText()Returns the text shown to the user (including placeholder formatting).
GetPreferredSizeSize GetPreferredSize(Size proposed)Calculates optimal size based on text, font, and theme padding.
ValidateDatabool ValidateData(out string message)Validates current text. Override for custom rules. Returns true if valid, false with error message.
SetValuevoid SetValue(object value)Sets text from a data-bound source. Clears Modified.
GetValueobject GetValue()Returns current text for data binding consumption.
ClearValuevoid ClearValue()Clears text and resets Modified to false.

Events

EventDescription
TextChangedRaised when the Text property value changes.
KeyDown / KeyPress / KeyUpStandard keyboard events.
EnterRaised when the control receives focus.
LeaveRaised 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

FileResponsibility
BeepTextBox.csMain entry, class declaration
BeepTextBox.Core.csConstructor, initialization, internal fields
BeepTextBox.Properties.csAll public properties
BeepTextBox.Events.csFocus/leave processing, validation triggers
BeepTextBox.Input.csKeyboard input, text operations
BeepTextBox.Methods.csGetDisplayText, ValidateData, SetValue, etc.
BeepTextBox.Drawing.csCustom painting for text, caret, selection
BeepTextBox.Effects.csFocus borders, hover states, shadows
BeepTextBox.Search.csSearch mode logic
BeepTextBox.Theme.csTheme application, color resolution