diff --git a/examples/MinimalWinFormiumApp/MyAboutForm.cs b/examples/MinimalWinFormiumApp/MyAboutForm.cs new file mode 100644 index 0000000000000000000000000000000000000000..bd031896d70690abd08079d3642d6d567ed50cca --- /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 0000000000000000000000000000000000000000..f069cd0d9405ff10fa1fbfa50db043c7562ffd53 --- /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 0000000000000000000000000000000000000000..ef7767ccd68f1f5907fb4c3a9010be882f67e071 --- /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 787ade2bd40263958a64a8fdfe4195f771030aec..e95db4cebf951f909a95e22aa08fa919ba2110fd 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 f9a0a85d20845c441f3d0bffdd4a7c39e270aa3d..9398a9ec1aef48c46bc56e84c8f64072f63ef8cf 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 44bd633c572a85127e8dd8027faf6ce63b5f42f7..448494bc14ae412cfffae266443f1b1801f6929f 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 9adff1c996fdcf8877f5fc68c36618a6d11d385c..f637a1a627dbaabeec92b2d688951e501722f764 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 d2ca4f5e2b6be7408370899487b4461372b55e48..aaea732c853617fa3f92d5a1e5ff22a3f549b1de 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()