Siticone Logo
Siticone UI
DOCS
v2025.12.15
Docs Advanced Text Area

Siticone Advanced Text Area

The SiticoneAdvancedTextArea is a sophisticated composite control that wraps a standard text input with powerful additional features. It includes a built-in statistics panel (Word/Character count), auto-sizing capabilities based on content, line highlighting, and a robust event system for granular change tracking (Insertions vs Deletions).

Statistics & Counters

The control features an integrated footer panel that automatically tracks text statistics in real-time. This eliminates the need to manually wire up `TextChanged` events to update external labels.

Property Type Description & Default Value
ShowCharacterCount bool True Toggles the visibility of the character counter in the footer panel.
ShowWordCount bool True Toggles the visibility of the word counter. Words are calculated using Regex \b\w+\b.
MaxCharacterLimit int 0 (No Limit) Sets a hard limit on input length. If > 0, the counter displays as "Current/Max". Input exceeding this limit is automatically trimmed.

Visual Behavior

Properties controlling the dynamic visual aspects of the editor, including highlighting and sizing.

Property Type Description
HighlightCurrentLine bool False If enabled, draws a subtle background highlight behind the line where the caret is currently positioned.
CurrentLineHighlightColor Color ARGB(15, 0, 0, 255) The color used for the line highlight. Supports alpha transparency for overlay effects.
AutoSizeToContent bool False If true, the control automatically expands or shrinks its height to fit the text content + footer panel.
ReadOnly bool False Sets the control to read-only mode and applies the ReadOnlyBackColor.
ReadOnlyBackColor Color WhiteSmoke Distinct background color applied automatically when ReadOnly is set to true.

Advanced Events

Unlike standard TextBoxes, this control provides highly specific events that detail what changed and where.

TextModified Event
// Fired whenever text changes, but provides context on the TYPE of change.
// Useful for implementing Undo/Redo stacks or syntax highlighting logic.
advancedTextArea1.TextModified += (s, e) => 
{
                switch (e.ModificationType)
    {
                case TextModificationType.Insertion:
                Console.WriteLine($"Inserted '{e.ModifiedText}' at index {e.Position}");
                break;
                case TextModificationType.Deletion:
                Console.WriteLine($"Deleted '{e.ModifiedText}' at index {e.Position}");
                break;
    }
};
TextStatisticsChanged Event
// Fired when character, word, or line counts change.
// This is throttled (250ms) to prevent performance issues during rapid typing.
advancedTextArea1.TextStatisticsChanged += (s, e) => 
{
    lblStatus.Text = $"Lines: {e.LineCount} | Words: {e.WordCount}";
    
                if (e.CharacterLimitPercentage > 90)
    {
        lblStatus.ForeColor = Color.Red; // Warn user if near limit
    }
};
TextSelectionChanged Event
// Fired when the caret moves or selection expands.
// Provides Line and Column numbers automatically.
advancedTextArea1.TextSelectionChanged += (s, e) => 
{
                Console.WriteLine($"Ln {e.LineNumber}, Col {e.ColumnNumber}");
                Console.WriteLine($"Selection Length: {e.SelectionLength}");
};
CharacterLimit Events
// CharacterLimitApproaching: Fired when 80% of MaxCharacterLimit is used.
// CharacterLimitReached: Fired when the limit is hit.
advancedTextArea1.CharacterLimitReached += (s, e) => 
{
                MessageBox.Show("You have reached the maximum allowed characters.");
};

Public Methods

The control exposes standard editing commands programmatically.

Method Description
AppendText(string text) Appends text to the end of the content and scrolls to it.
Clear() Clears all text content.
Undo() / ClearUndo() Performs an undo operation or clears the undo buffer.
Copy() / Cut() / Paste() Standard clipboard operations.
Select(int start, int length) Selects a specific range of text.
SelectAll() Selects the entire text content.
GetLineFromCharIndex(int) Returns the line number (0-based) containing the specified character index.
GetFirstCharIndexFromLine(int) Returns the index of the first character in the specified line.

Detailed Examples

Example 1: Auto-Expanding Tweet Editor

This example configures the control to behave like a social media input box: it expands as you type, enforces a character limit, and warns the user when they are running out of space.

C# - Social Media Input
private void InitializeTweetEditor()
{
                // 1. Configure Limits and Auto-Sizing
    tweetBox.MaxCharacterLimit = 280;
    tweetBox.AutoSizeToContent = true;
    tweetBox.Width = 400;
    tweetBox.MinimumSize = new Size(400, 100); // Start small
    
                // 2. Configure Statistics Display
    tweetBox.ShowWordCount = false; // Only show chars
    tweetBox.ShowCharacterCount = true;
    
                // 3. Handle "Approaching Limit" to change UI color
    tweetBox.CharacterLimitApproaching += (s, e) => 
    {
                // Change counter panel text color or background to warn user
                // (Note: You might need to access the controls or use a separate label)
                SystemSounds.Beep.Play();
    };
    
                // 4. Handle Text Modification for Hashtag highlighting (Conceptual)
    tweetBox.TextModified += (s, e) =>
    {
                if (e.ModificationType == TextModificationType.Insertion && 
            e.ModifiedText == "#")
        {
                // Logic to trigger hashtag autocomplete popup
                ShowHashtagAutocomplete();
        }
    };
}

Example 2: Code Editor Configuration

Sets up the control to look and behave like a simple code editor with line highlighting and monospaced fonts.

C# - Code Editor Setup
private void SetupCodeEditor()
{
                // 1. Visual Style
    editor.Font = new Font("Consolas", 10f);
    editor.BackColor = Color.FromArgb(30, 30, 30);
    editor.ForeColor = Color.Gainsboro;
    
                // 2. Enable Line Highlighting
    editor.HighlightCurrentLine = true;
    editor.CurrentLineHighlightColor = Color.FromArgb(20, 255, 255, 255); // Subtle transparent white
    
                // 3. Statistics
    editor.ShowCharacterCount = false;
    editor.ShowWordCount = false; // Hide default counters
    
                // 4. Track Cursor Position for Status Bar
    editor.TextSelectionChanged += (s, e) =>
    {
                // Update your main form's status strip
        lblCursorPos.Text = $"Ln {e.LineNumber}, Col {e.ColumnNumber}";
    };
    
                // 5. Track Line Changes
    editor.LineChanged += (s, e) =>
    {
                Console.WriteLine($"Moved from Line {e.PreviousLineNumber} to {e.CurrentLineNumber}");
    };
}