- runtime:仿真 WinForms 子集(Form、Button、Label、TextBox、ComboBox、 GroupBox、Timer、MessageBox、界面线程消息循环、跨线程检查)、 教材设备类库(DeviceCtrlHelper、LED 控件)、运行器(常驻编译服务 + 运行模式) - server:Bun + Hono,WebSocket 会话,每次运行一个进程,消息转发 - web:Vue + Naive UI,WinForms 风格窗体渲染、MessageBox、实训台 LED 屏 - 端到端测试与 100 个程序并发的压力测试 - 教材逐任务摘要(docs/教材摘要) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
using System.Drawing;
|
|
using System.Text.Json.Nodes;
|
|
using Sim.Host;
|
|
|
|
namespace System.Windows.Forms;
|
|
|
|
public abstract class TextBoxBase : Control
|
|
{
|
|
private bool _multiline;
|
|
private bool _readOnly;
|
|
private BorderStyle _borderStyle = BorderStyle.Fixed3D;
|
|
|
|
public bool Multiline
|
|
{
|
|
get => _multiline;
|
|
set => SetProp(ref _multiline, value, nameof(Multiline));
|
|
}
|
|
|
|
public bool ReadOnly
|
|
{
|
|
get => _readOnly;
|
|
set => SetProp(ref _readOnly, value, nameof(ReadOnly));
|
|
}
|
|
|
|
public BorderStyle BorderStyle
|
|
{
|
|
get => _borderStyle;
|
|
set => SetProp(ref _borderStyle, value, nameof(BorderStyle));
|
|
}
|
|
|
|
public int MaxLength { get; set; } = 32767;
|
|
public bool WordWrap { get; set; } = true;
|
|
public bool HideSelection { get; set; } = true;
|
|
public bool Modified { get; set; }
|
|
public int SelectionStart { get; set; }
|
|
public int SelectionLength { get; set; }
|
|
public int TextLength => Text.Length;
|
|
|
|
public string[] Lines
|
|
{
|
|
get => Text.Replace("\r\n", "\n").Split('\n');
|
|
set => Text = string.Join("\r\n", value);
|
|
}
|
|
|
|
public void AppendText(string text) => Text += text;
|
|
public void Clear() => Text = "";
|
|
public void SelectAll() { }
|
|
public void Select(int start, int length) { }
|
|
public void ScrollToCaret() { }
|
|
|
|
protected override void OnUserAction(UserAction action)
|
|
{
|
|
if (action.Action == "text" && !ReadOnly)
|
|
{
|
|
Modified = true;
|
|
SetTextFromUser(action.Value ?? "");
|
|
return;
|
|
}
|
|
base.OnUserAction(action);
|
|
}
|
|
|
|
protected override void WriteProps(JsonObject props)
|
|
{
|
|
base.WriteProps(props);
|
|
props["Multiline"] = _multiline;
|
|
props["ReadOnly"] = _readOnly;
|
|
props["BorderStyle"] = _borderStyle.ToString();
|
|
}
|
|
}
|
|
|
|
public class TextBox : TextBoxBase
|
|
{
|
|
private char _passwordChar;
|
|
private bool _useSystemPasswordChar;
|
|
private ScrollBars _scrollBars;
|
|
|
|
protected override Size DefaultSize => new(100, 21);
|
|
|
|
public char PasswordChar
|
|
{
|
|
get => _passwordChar;
|
|
set => SetProp(ref _passwordChar, value, nameof(PasswordChar));
|
|
}
|
|
|
|
public bool UseSystemPasswordChar
|
|
{
|
|
get => _useSystemPasswordChar;
|
|
set => SetProp(ref _useSystemPasswordChar, value, nameof(UseSystemPasswordChar));
|
|
}
|
|
|
|
public ScrollBars ScrollBars
|
|
{
|
|
get => _scrollBars;
|
|
set => SetProp(ref _scrollBars, value, nameof(ScrollBars));
|
|
}
|
|
|
|
public HorizontalAlignment TextAlign { get; set; }
|
|
|
|
protected override void WriteProps(JsonObject props)
|
|
{
|
|
base.WriteProps(props);
|
|
props["PasswordChar"] = PropValue.From(_passwordChar);
|
|
props["UseSystemPasswordChar"] = _useSystemPasswordChar;
|
|
props["ScrollBars"] = _scrollBars.ToString();
|
|
}
|
|
}
|
|
|
|
public enum HorizontalAlignment { Left, Right, Center }
|