|
| 1 | +<p align="center"> |
| 2 | + <img src="./artworks/WinFormiumLogo.png" width="144" /> |
| 3 | +</p> |
| 4 | +<h1 align="center">NanUI 项目</h1> |
| 5 | +<p align="center"><strong>用 HTML, CSS 和 JavaScript 轻松构建功能强大的 WinForm 应用程序。</strong></p> |
| 6 | + |
| 7 | +# NanUI |
| 8 | + |
| 9 | +Click [[Here]](https://github.com/XuanchenLin/NanUI) to see the English version. |
| 10 | + |
| 11 | + |
| 12 | +[](https://github.com/XuanchenLin/NanUI/actions/workflows/main.yml) |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## ⭐ 关于 |
| 17 | + |
| 18 | +NanUI 是 .NET 平台上的一个开源框架,用于使用 HTML5、CSS3 和 JavaScript 创建 WinForm 应用程序的用户界面。 它基于 [Xilium.CefGlue](https://bitbucket.org/xilium/xilium.cefglue/wiki/Home) 项目,该项目是 [Chromium Embedded Framework (CEF)](https://bitbucket.org/chromiumembedded/cef) 的 .NET 实现。 |
| 19 | + |
| 20 | +如果您正在寻找一个用于创建具有现代用户界面的 WinForm 应用程序的框架,NanUI 是一个不错的选择。 您可以使用 HTML、CSS 和 JavaScript 创建用户界面,并使用 C# 编写应用程序的业务逻辑。 |
| 21 | + |
| 22 | +**如果您喜欢 👍,请给 NanUI 项目一颗星 ⭐。** |
| 23 | + |
| 24 | +如果这个项目对你有帮助,请考虑资助它。 |
| 25 | + |
| 26 | +[](docs/assets/qrcode.png) |
| 27 | +[](docs/assets/qrcode.png) |
| 28 | + |
| 29 | +## ✨ 推荐给对 WebView2 感兴趣的开发者 |
| 30 | + |
| 31 | +如果您觉得基于 CEF 的 NanUI 过重,那么您现在就可以尝试 **WinFormedge** 项目。它是一个基于 [WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) 作为内核的、轻量级的 WinForm 框架。适用于那些不想集成 libcef 的开发者,使用 WinFormege 并配合 Windows 系统自带的 WebView2 将非常有效地降低应用程序发布包的大小。 |
| 32 | + |
| 33 | +经过测试使用 .NET 8.0 x64 + WinFormedge 应用打包使用 ZIP 压缩后大小仅 36MB,而使用 NanUI 打包的应用程序压缩后至少 125M。 |
| 34 | + |
| 35 | +但需要注意的是使用 WinFormedge 创建的应用程序只能在 Windows 10 和 Windows 11 上运行,而 NanUI 支持 Windows 7 SP1 及更高版本。 |
| 36 | + |
| 37 | +- GitHub - [WinFormedge](https://github.com/XuanchenLin/WinFormedge) |
| 38 | +- Gitee - [WinFormedge](https://gitee.com/linxuanchen/WinFormedge) |
| 39 | + |
| 40 | +## 🖥️ 环境要求 |
| 41 | + |
| 42 | +**开发环境** |
| 43 | + |
| 44 | +- .NET Framework 4.6.2 或更高版本 / .NET 6.0 或更高版本 |
| 45 | +- Visual Studio 2019 或更高版本(强烈建议使用 VS2022) |
| 46 | + |
| 47 | +**部署环境** |
| 48 | + |
| 49 | +- Microsoft Windows 7 Service Pack 1 或更高版本 |
| 50 | +- .Net Framework 4.6.2 或更高版本 |
| 51 | +- .NET 6.0 需要 Windows 7 Service Pack 1 或更高版本 |
| 52 | +- .NET 7.0/8.0/9.0 需要 Windows 10 或 Windows 11 |
| 53 | + |
| 54 | +这是一个 **仅限 Windows** 的框架,所以它目前不能在 Linux 或者 MacOS 环境运行。 |
| 55 | + |
| 56 | +支持的最低 Windows 版本是 Windows 7 Service Pack 1,并且 Windows 7 不支持某些功能(例如 DirectComposition 离屏渲染)。 |
| 57 | + |
| 58 | +## 🧰 入门 |
| 59 | + |
| 60 | +按照以下步骤即可创建一个简单的 NanUI 应用程序: |
| 61 | + |
| 62 | +**1. 通过默认模板创建一个 WinForm 应用程序。** |
| 63 | + |
| 64 | +**2. 安装 NanUI NuGet 包** |
| 65 | + |
| 66 | +打开 NuGet 包管理器来安装或使用 NuGet 包管理器控制台,然后运行以下命令来安装 WinFormium nuget 包: |
| 67 | + |
| 68 | +```powershell |
| 69 | +PM> Install-Package NetDimension.NanUI |
| 70 | +``` |
| 71 | + |
| 72 | +安装 NanUI 所依赖的 Chromium Embedded Framework 依赖项: |
| 73 | + |
| 74 | +```powershell |
| 75 | +PM> Install-Package NetDimension.NanUI.Runtime |
| 76 | +``` |
| 77 | + |
| 78 | +CEF 运行库巨大,再加上众所周知的原因,中国内地玩家请自行设置 NuGet 使用国内镜像。 |
| 79 | + |
| 80 | +- **Azure CDN** - https://nuget.cdn.azure.cn/v3/index.json |
| 81 | +- **华为云** - https://repo.huaweicloud.com/repository/nuget/v3/index.json |
| 82 | + |
| 83 | +**3. 一个基本的 NanUI 应用程序需要以下代码:** |
| 84 | + |
| 85 | +按如下示例修改 **Program.cs** 文件中的代码: |
| 86 | + |
| 87 | +```csharp |
| 88 | +using NetDimension.NanUI; |
| 89 | + |
| 90 | +class Program |
| 91 | +{ |
| 92 | + [STAThread] |
| 93 | + static void Main(string[] args) |
| 94 | + { |
| 95 | + var builder = NanUIApp.CreateBuilder(); |
| 96 | + |
| 97 | + builder.UseNanUIApp<MyApp>(); |
| 98 | + |
| 99 | + var app = builder.Build(); |
| 100 | + |
| 101 | + app.Run(); |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +创建一个类继承 **AppStartup** 来配置应用程序: |
| 107 | + |
| 108 | +```csharp |
| 109 | +using NetDimension.NanUI; |
| 110 | + |
| 111 | +class MyAPP : AppStartup |
| 112 | +{ |
| 113 | + protected override MainWindowCreationAction? UseMainWindow(MainWindowOptions opts) |
| 114 | + { |
| 115 | + // 设置应用程序的主窗体 |
| 116 | + return opts.UseMainFormium<MyWindow>(); |
| 117 | + } |
| 118 | + |
| 119 | + protected override void ProgramMain(string[] args) |
| 120 | + { |
| 121 | + // Main函数中的代码应该在这里,该函数只在主进程中运行。这样可以防止子进程运行一些不正确的初始化代码。 |
| 122 | + ApplicationConfiguration.Initialize(); |
| 123 | + } |
| 124 | + |
| 125 | + protected override void ConfigurationChromiumEmbedded(ChromiumEnvironmentBuiler cef) |
| 126 | + { |
| 127 | + // 在此处配置 Chromium Embedded Framwork |
| 128 | + } |
| 129 | + |
| 130 | + protected override void ConfigureServices(IServiceCollection services) |
| 131 | + { |
| 132 | + // 在这里配置该应用程序的服务 |
| 133 | + } |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +创建一个类实现 **Formium**,用于配置应用程序的主窗口: |
| 138 | + |
| 139 | +```csharp |
| 140 | +using NetDimension.NanUI; |
| 141 | +using NetDimension.NanUI.Forms; |
| 142 | + |
| 143 | +class MyWindow : Formium |
| 144 | +{ |
| 145 | + public MyWindow() |
| 146 | + { |
| 147 | + Url = "https://www.google.com"; |
| 148 | + } |
| 149 | + |
| 150 | + protected override FormStyle ConfigureWindowStyle(WindowStyleBuilder builder) |
| 151 | + { |
| 152 | + // 此处配置窗口的样式和属性,或留空以使用默认样式 |
| 153 | +
|
| 154 | + var style = builder.UseSystemForm(); |
| 155 | + |
| 156 | + style.TitleBar = false; |
| 157 | + |
| 158 | + style.DefaultAppTitle = "My first WinFomrim app"; |
| 159 | + |
| 160 | + return style; |
| 161 | + } |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +**4. 生成并运行你的第一个 NanUI 应用程序** |
| 166 | + |
| 167 | +## 📖 文档 |
| 168 | + |
| 169 | +有关更多信息,请参阅 - [文档](docs/README.md)。 |
| 170 | + |
| 171 | +## 🤖 示例代码 |
| 172 | + |
| 173 | +- [Minimal WinFormium App](./examples/MinimalWinFormiumApp) - 介绍 NanUI 的基本用法。 |
| 174 | + |
| 175 | +## 🔗 第三方库引用和工具集 |
| 176 | + |
| 177 | +- CEF - [https://bitbucket.org/chromiumembedded/cef](https://bitbucket.org/chromiumembedded/cef) |
| 178 | +- Xilium.CefGlue - [https://gitlab.com/xiliumhq/chromiumembedded/cefglue](https://gitlab.com/xiliumhq/chromiumembedded/cefglue) |
| 179 | +- Vanara.Library - [https://github.com/dahall/Vanara/](https://github.com/dahall/Vanara/) |
| 180 | +- Vortice.Windows - [https://github.com/amerkoleci/Vortice.Windows](https://github.com/amerkoleci/Vortice.Windows) |
| 181 | +- SkiaSharp - [https://github.com/mono/SkiaSharp](https://github.com/mono/SkiaSharp) |
| 182 | +- React - [https://github.com/facebook/react](https://github.com/facebook/react) |
| 183 | +- React-Router - [https://github.com/remix-run/react-router](https://github.com/remix-run/react-router) |
| 184 | +- Vite - [https://github.com/vitejs/vite](https://github.com/vitejs/vite) |
| 185 | + |
0 commit comments