From eb6f7658f1eaf1b7567da436308ab0ab13e1c8ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B1=AA=E6=B1=AA=E6=B1=AA?= <102617640@qq.com>
Date: Tue, 21 Jul 2026 09:10:35 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=BF=E6=8D=A2=E7=B3=BB?=
=?UTF-8?q?=E7=BB=9F=E9=BB=98=E8=AE=A4=E5=85=B3=E4=BA=8E=E7=AA=97=E5=8F=A3?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/MinimalWinFormiumApp/MyAboutForm.cs | 64 +++++++++++++++++++
.../MyAboutForm2.Designer.cs | 43 +++++++++++++
examples/MinimalWinFormiumApp/MyAboutForm2.cs | 21 ++++++
examples/MinimalWinFormiumApp/MyWindow.cs | 8 ++-
src/Sources/Browser/WebView/WebView.cs | 30 +++++++--
src/Sources/Formium/Formium.Members.cs | 2 +-
src/Sources/Formium/Formium.Overrides.cs | 2 +
src/Sources/Formium/Formium.cs | 2 +-
8 files changed, 163 insertions(+), 9 deletions(-)
create mode 100644 examples/MinimalWinFormiumApp/MyAboutForm.cs
create mode 100644 examples/MinimalWinFormiumApp/MyAboutForm2.Designer.cs
create mode 100644 examples/MinimalWinFormiumApp/MyAboutForm2.cs
diff --git a/examples/MinimalWinFormiumApp/MyAboutForm.cs b/examples/MinimalWinFormiumApp/MyAboutForm.cs
new file mode 100644
index 0000000..bd03189
--- /dev/null
+++ b/examples/MinimalWinFormiumApp/MyAboutForm.cs
@@ -0,0 +1,64 @@
+// THIS FILE IS PART OF NanUI PROJECT
+// THE NanUI PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
+// COPYRIGHTS (C) Xuanchen Lin. ALL RIGHTS RESERVED.
+// GITHUB: https://github.com/XuanchenLin/NanUI
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NetDimension.NanUI;
+using NetDimension.NanUI.Forms;
+
+namespace MinimalWinFormiumApp;
+public class MyAboutForm : Formium
+{
+ public MyAboutForm()
+ {
+ Loaded += MyAbortForm_Loaded; ;
+ }
+
+ private void MyAbortForm_Loaded(object? sender, BrowserEventArgs e)
+ {
+ AppTitle = "test";
+ Url = "https://www.bing.com";
+ }
+
+ protected override bool DisableAboutMenu => true;
+ protected override FormStyle ConfigureWindowStyle(WindowStyleBuilder builder)
+ {
+ var style = builder.UseSystemForm();
+
+
+ style.Size = new System.Drawing.Size(1440, 900);
+
+ style.DefaultAppTitle = "测试";
+
+ style.StartCentered = StartCenteredMode.CenterScreen;
+
+ // 移除系统窗体的标题栏
+ // To remove the title bar of a system window and achieve a borderless form
+ style.TitleBar = true;
+ style.BackdropType = SystemFormBackdropType.Mica;
+
+
+ // 指定系统深浅色主题模式,默认将自动检测当前系统的深浅色主题模式。也可以手动指定
+ // Specify the system's light or dark theme mode. By default, it will automatically detect the current system's theme mode. It can also be manually specified.
+ //style.ColorMode = FormiumColorMode.Dark;
+
+ // 是否启用网页的页面标题
+ // Whether to enable the page title of the webpage.
+ style.UsePageTitle = true;
+
+ //style.StartCentered = true;
+
+ // 是否启用Kiosk模式,启用后将禁用任务栏
+ // Whether to enable Kiosk mode, which disables the taskbar when enabled.
+ //var style = builder.UseKisokForm();
+ //style.DisableTaskBar = true;
+
+ this.Size = new Size(1440, 900);
+
+ return style;
+ }
+}
diff --git a/examples/MinimalWinFormiumApp/MyAboutForm2.Designer.cs b/examples/MinimalWinFormiumApp/MyAboutForm2.Designer.cs
new file mode 100644
index 0000000..f069cd0
--- /dev/null
+++ b/examples/MinimalWinFormiumApp/MyAboutForm2.Designer.cs
@@ -0,0 +1,43 @@
+// THIS FILE IS PART OF NanUI PROJECT
+// THE NanUI PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
+// COPYRIGHTS (C) Xuanchen Lin. ALL RIGHTS RESERVED.
+// GITHUB: https://github.com/XuanchenLin/NanUI
+
+namespace MinimalWinFormiumApp;
+
+partial class MyAboutForm2
+{
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Text = "MyAboutForm2";
+ }
+
+ #endregion
+}
\ No newline at end of file
diff --git a/examples/MinimalWinFormiumApp/MyAboutForm2.cs b/examples/MinimalWinFormiumApp/MyAboutForm2.cs
new file mode 100644
index 0000000..ef7767c
--- /dev/null
+++ b/examples/MinimalWinFormiumApp/MyAboutForm2.cs
@@ -0,0 +1,21 @@
+// THIS FILE IS PART OF NanUI PROJECT
+// THE NanUI PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
+// COPYRIGHTS (C) Xuanchen Lin. ALL RIGHTS RESERVED.
+// GITHUB: https://github.com/XuanchenLin/NanUI
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+
+namespace MinimalWinFormiumApp;
+public partial class MyAboutForm2 : Form
+{
+ public MyAboutForm2()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/examples/MinimalWinFormiumApp/MyWindow.cs b/examples/MinimalWinFormiumApp/MyWindow.cs
index 787ade2..e95db4c 100644
--- a/examples/MinimalWinFormiumApp/MyWindow.cs
+++ b/examples/MinimalWinFormiumApp/MyWindow.cs
@@ -19,7 +19,7 @@ internal class MyWindow : Formium
{
//默认测试,加载普通网页
//Default test, load web page
- //Url = "https://www.bing.com";
+ Url = "https://www.bing.com";
//测试加载本地资源
//Test loading local resources
@@ -33,6 +33,10 @@ internal class MyWindow : Formium
//Error address test specifies the address of the error page. If the page fails to load, WinFormium's built-in error page will be automatically displayed.
//Url = "http://static1.app.local/";
+ //替换系统默认关于窗口,支持Formium和Form
+ //Replace default about window, support both Formium and Form
+ AboutForm = typeof(MyAboutForm);//MyAboutForm2
+
//注意,默认没有指定任何Url,新版WinFormium将会自动加载一个欢迎页面。
//If no URL is specified, WinFormium will automatically load a welcome page.
@@ -230,7 +234,7 @@ internal class MyWindow : Formium
// 移除系统窗体的标题栏
// To remove the title bar of a system window and achieve a borderless form
- style.TitleBar = false;
+ style.TitleBar = true;
//style.BackdropType = SystemFormBackdropType.Mica;
diff --git a/src/Sources/Browser/WebView/WebView.cs b/src/Sources/Browser/WebView/WebView.cs
index f9a0a85..9398a9e 100644
--- a/src/Sources/Browser/WebView/WebView.cs
+++ b/src/Sources/Browser/WebView/WebView.cs
@@ -39,7 +39,8 @@ internal partial class WebView
public string Url
{
get => Browser?.GetMainFrame()?.Url ?? _url;
- set {
+ set
+ {
_url = $"{value}".Trim();
TaskAction.Run(() =>
@@ -109,7 +110,8 @@ internal partial class WebView
public void ResizeWebView(int width, int height)
{
- WebViewHost.InvokeOnUIThread(() => {
+ WebViewHost.InvokeOnUIThread(() =>
+ {
ResizeWebViewCore(width, height);
});
}
@@ -221,13 +223,31 @@ internal partial class WebView
return RegisterJavaScriptObject(handle, name, jsHostObject.HostObject);
}
- public void ShowAboutDialog()
+ public void ShowAboutDialog(Type abortFormType)
{
WebViewHost.InvokeOnUIThread(() =>
{
- var about = new AboutForm();
+ if (abortFormType == null)
+ {
+ var about = new AboutForm();
- about.ShowDialog(WebViewHost.Formium);
+ about.ShowDialog(WebViewHost.Formium);
+ }
+ else
+ {
+ var instance = Activator.CreateInstance(abortFormType);
+ if (instance != null)
+ {
+ if (instance is Form frm)
+ {
+ frm.ShowDialog(WebViewHost.Formium);
+ }
+ else if (instance is Formium fm)
+ {
+ fm.ShowDialog(WebViewHost.Formium);
+ }
+ }
+ }
});
}
diff --git a/src/Sources/Formium/Formium.Members.cs b/src/Sources/Formium/Formium.Members.cs
index 44bd633..448494b 100644
--- a/src/Sources/Formium/Formium.Members.cs
+++ b/src/Sources/Formium/Formium.Members.cs
@@ -711,7 +711,7 @@ public partial class Formium : IDisposable, IWin32Window
if (cmd == SYSMENU_ABOUT_ID)
{
- WebView.ShowAboutDialog();
+ WebView.ShowAboutDialog(AboutForm);
}
}
diff --git a/src/Sources/Formium/Formium.Overrides.cs b/src/Sources/Formium/Formium.Overrides.cs
index 9adff1c..f637a1a 100644
--- a/src/Sources/Formium/Formium.Overrides.cs
+++ b/src/Sources/Formium/Formium.Overrides.cs
@@ -40,6 +40,8 @@ public partial class Formium
protected virtual bool DisableAboutMenu => false;
+ protected Type AboutForm = null;
+
///
/// Gets or sets the system menu will show when right clicking in dragable regions.
///
diff --git a/src/Sources/Formium/Formium.cs b/src/Sources/Formium/Formium.cs
index d2ca4f5..aaea732 100644
--- a/src/Sources/Formium/Formium.cs
+++ b/src/Sources/Formium/Formium.cs
@@ -916,7 +916,7 @@ public abstract partial class Formium
///
public void ShowAboutDialog()
{
- WebView.ShowAboutDialog();
+ WebView.ShowAboutDialog(AboutForm);
}
public Form GetHostWindow()
--
Gitee