- 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>
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sim.Host;
|
|
|
|
namespace System.Windows.Forms;
|
|
|
|
public static class Application
|
|
{
|
|
internal static readonly List<Form> OpenFormsList = new();
|
|
private static bool _exitRequested;
|
|
|
|
public static FormCollection OpenForms { get; } = new();
|
|
|
|
public static string StartupPath => AppContext.BaseDirectory.TrimEnd('/', '\\');
|
|
public static string ExecutablePath => System.IO.Path.Combine(StartupPath, "app.exe");
|
|
public static string ProductName => "WindowsFormsApplication";
|
|
|
|
public static void EnableVisualStyles() { }
|
|
|
|
public static void SetCompatibleTextRenderingDefault(bool defaultValue) { }
|
|
|
|
public static void SetHighDpiMode(object mode) { }
|
|
|
|
/// <summary>显示主窗体并运行消息循环,直到主窗体关闭或调用 Application.Exit()</summary>
|
|
public static void Run(Form mainForm)
|
|
{
|
|
mainForm.Show();
|
|
SimHost.Ui.RunUntil(() => _exitRequested || mainForm.IsClosed);
|
|
Exit();
|
|
}
|
|
|
|
public static void Run()
|
|
{
|
|
SimHost.Ui.RunUntil(() => _exitRequested);
|
|
}
|
|
|
|
public static void Exit()
|
|
{
|
|
_exitRequested = true;
|
|
foreach (var form in OpenFormsList.ToArray()) form.CloseCore(CloseReason.ApplicationExitCall);
|
|
SimHost.Ui.Wake();
|
|
}
|
|
|
|
public static void ExitThread() => Exit();
|
|
|
|
public static void DoEvents() => SimHost.Ui.DoEvents();
|
|
|
|
public sealed class FormCollection : IEnumerable<Form>
|
|
{
|
|
public int Count => OpenFormsList.Count;
|
|
public Form this[int index] => OpenFormsList[index];
|
|
public Form? this[string name] => OpenFormsList.Find(f => f.Name == name);
|
|
public IEnumerator<Form> GetEnumerator() => OpenFormsList.GetEnumerator();
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
}
|
|
}
|