TextView
The TextView widget displays multi-line text with scrolling capabilities. Perfect for logs, chat messages, or any scrollable text content.
Overview
Section titled “Overview”TextView maintains a list of text lines and provides scrolling functionality. It’s ideal for displaying logs, chat messages, or any content that may exceed the visible area.
Properties
Section titled “Properties”AutoScroll (bool)
Section titled “AutoScroll (bool)”Whether to automatically scroll to the bottom when new lines are added (default: true).
textView.AutoScroll = true;WordWrap (bool)
Section titled “WordWrap (bool)”Whether to wrap long lines (default: false).
textView.WordWrap = true;ScrollOffset (int, read-only)
Section titled “ScrollOffset (int, read-only)”The current scroll offset (number of lines scrolled).
int offset = textView.ScrollOffset;LineCount (int, read-only)
Section titled “LineCount (int, read-only)”The total number of lines.
int count = textView.LineCount;Methods
Section titled “Methods”AppendLine(string text)
Section titled “AppendLine(string text)”Adds a line of text to the view.
textView.AppendLine("New message");AppendLines(IEnumerable<string> lines)
Section titled “AppendLines(IEnumerable<string> lines)”Adds multiple lines of text.
textView.AppendLines(new[] { "Line 1", "Line 2", "Line 3" });SetText(string text)
Section titled “SetText(string text)”Sets the text content, replacing all existing lines.
textView.SetText("Line 1\nLine 2\nLine 3");Clear()
Section titled “Clear()”Clears all text.
textView.Clear();Scrolling Methods
Section titled “Scrolling Methods”ScrollUp(int lines = 1): Scroll upScrollDown(int lines = 1): Scroll downScrollToTop(): Scroll to topScrollToBottom(): Scroll to bottom
Keyboard Navigation
Section titled “Keyboard Navigation”- Up Arrow: Scroll up one line
- Down Arrow: Scroll down one line
- Page Up: Scroll up one page
- Page Down: Scroll down one page
- Home: Scroll to top
- End: Scroll to bottom
Usage Example
Section titled “Usage Example”var textView = new TextView{ X = 2, Y = 2, Width = 70, Height = 15, ForegroundColor = Color.White, BackgroundColor = Color.Black, AutoScroll = true};
textView.AppendLine("[System] Welcome!");textView.AppendLine("[User] Hello");textView.AppendLine("[Bot] Hi there!");
// Disable auto-scroll to allow manual scrollingtextView.AutoScroll = false;textView.ScrollToTop();Common Patterns
Section titled “Common Patterns”Chat Interface
Section titled “Chat Interface”textView.AppendLine($"[{DateTime.Now:HH:mm:ss}] {username}: {message}");Log Viewer
Section titled “Log Viewer”textView.AppendLine($"[{level}] {message}");Related Widgets
Section titled “Related Widgets”- Label - For single-line or simple text
- TextField - For text input
- Base Widget - Base class documentation