diff --git a/SunnyUI/Controls/UIProgressIndicator.cs b/SunnyUI/Controls/UIProgressIndicator.cs index e9046095..9b539e8d 100644 --- a/SunnyUI/Controls/UIProgressIndicator.cs +++ b/SunnyUI/Controls/UIProgressIndicator.cs @@ -19,6 +19,7 @@ * 2020-01-01: V2.2.0 增加文件说明 * 2020-04-25: V2.2.4 更新主题配置类 * 2022-03-19: V3.1.1 重构主题配色 + * 2022-12-18: V3.3.0 增加Active属性,是否激活动态显示 ******************************************************************************/ using System; @@ -42,7 +43,6 @@ namespace Sunny.UI timer = new Timer(); timer.Interval = 200; timer.Tick += timer_Tick; - timer.Start(); ShowText = false; ShowRect = false; @@ -50,6 +50,14 @@ namespace Sunny.UI foreColor = UIStyles.Blue.ProgressIndicatorColor; } + [Description("是否激活动态显示"), Category("SunnyUI")] + [DefaultValue(false)] + public bool Active + { + get => timer.Enabled; + set => timer.Enabled = value; + } + protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs index 7420a3e6..10274794 100644 --- a/SunnyUI/Forms/UIForm.cs +++ b/SunnyUI/Forms/UIForm.cs @@ -1874,6 +1874,23 @@ namespace Sunny.UI UIWaitFormService.SetDescription(desc); } + /// + /// 显示等待提示窗 + /// + /// 大小 + public void ShowProcessForm(int size = 200) + { + UIProcessIndicatorFormService.ShowForm(size); + } + + /// + /// 隐藏等待提示窗 + /// + public void HideProcessForm() + { + UIProcessIndicatorFormService.HideForm(); + } + /// /// 正确信息提示框 /// diff --git a/SunnyUI/Forms/UIFormService.cs b/SunnyUI/Forms/UIFormService.cs index 1d941fe9..5aca9ff9 100644 --- a/SunnyUI/Forms/UIFormService.cs +++ b/SunnyUI/Forms/UIFormService.cs @@ -85,6 +85,72 @@ namespace Sunny.UI } } + public class UIProcessIndicatorFormService + { + private static bool IsRun; + + public static void ShowForm(int size = 100) + { + if (IsRun) return; + Instance.CreateForm(size); + IsRun = true; + } + + public static void HideForm() + { + if (!IsRun) return; + Instance.CloseForm(); + IsRun = false; + } + + private static UIProcessIndicatorFormService _instance; + private static readonly object syncLock = new object(); + + private static UIProcessIndicatorFormService Instance + { + get + { + if (_instance == null) + { + lock (syncLock) + { + _instance = new UIProcessIndicatorFormService(); + } + } + + return _instance; + } + } + + private Thread thread; + private UIProcessIndicatorForm form; + + private void CreateForm(int size = 200) + { + CloseForm(); + thread = new Thread(delegate () + { + form = new UIProcessIndicatorForm(); + form.Size = new System.Drawing.Size(size, size); + form.ShowInTaskbar = false; + form.TopMost = true; + form.Render(); + Application.Run(form); + IsRun = false; + }); + + thread.Start(); + } + + private void CloseForm() + { + if (form != null && form.Visible) + { + form.NeedClose = true; + } + } + } + public class UIStatusFormService { private static bool IsRun; diff --git a/SunnyUI/Forms/UIProcessIndicatorForm.Designer.cs b/SunnyUI/Forms/UIProcessIndicatorForm.Designer.cs new file mode 100644 index 00000000..8cbea115 --- /dev/null +++ b/SunnyUI/Forms/UIProcessIndicatorForm.Designer.cs @@ -0,0 +1,74 @@ +namespace Sunny.UI +{ + partial class UIProcessIndicatorForm + { + /// + /// 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.uiProgressIndicator1 = new Sunny.UI.UIProgressIndicator(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // uiProgressIndicator1 + // + this.uiProgressIndicator1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.uiProgressIndicator1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.uiProgressIndicator1.Location = new System.Drawing.Point(5, 5); + this.uiProgressIndicator1.MinimumSize = new System.Drawing.Size(1, 1); + this.uiProgressIndicator1.Name = "uiProgressIndicator1"; + this.uiProgressIndicator1.Size = new System.Drawing.Size(190, 190); + this.uiProgressIndicator1.TabIndex = 0; + this.uiProgressIndicator1.Text = "uiProgressIndicator1"; + this.uiProgressIndicator1.ZoomScaleRect = new System.Drawing.Rectangle(0, 0, 0, 0); + // + // timer1 + // + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // UIProcessIndicatorForm + // + this.AllowShowTitle = false; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.ClientSize = new System.Drawing.Size(200, 200); + this.Controls.Add(this.uiProgressIndicator1); + this.Name = "UIProcessIndicatorForm"; + this.Padding = new System.Windows.Forms.Padding(2, 0, 2, 2); + this.ShowTitle = false; + this.Text = "UIProcessIndicatorForm"; + this.ZoomScaleRect = new System.Drawing.Rectangle(15, 15, 800, 450); + this.ResumeLayout(false); + + } + + #endregion + + private UIProgressIndicator uiProgressIndicator1; + private System.Windows.Forms.Timer timer1; + } +} \ No newline at end of file diff --git a/SunnyUI/Forms/UIProcessIndicatorForm.cs b/SunnyUI/Forms/UIProcessIndicatorForm.cs new file mode 100644 index 00000000..a1a9512f --- /dev/null +++ b/SunnyUI/Forms/UIProcessIndicatorForm.cs @@ -0,0 +1,26 @@ +using System.ComponentModel; + +namespace Sunny.UI +{ + public partial class UIProcessIndicatorForm : UIForm + { + public UIProcessIndicatorForm() + { + InitializeComponent(); + timer1.Start(); + uiProgressIndicator1.Active = true; + } + + private void timer1_Tick(object sender, System.EventArgs e) + { + if (NeedClose) + { + uiProgressIndicator1.Active = false; + Close(); + } + } + + [DefaultValue(false), Browsable(false)] + public bool NeedClose { get; set; } + } +} diff --git a/SunnyUI/Forms/UIProcessIndicatorForm.resx b/SunnyUI/Forms/UIProcessIndicatorForm.resx new file mode 100644 index 00000000..d7310886 --- /dev/null +++ b/SunnyUI/Forms/UIProcessIndicatorForm.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index 0b86d564..5767cd5c 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -1151,6 +1151,23 @@ namespace Sunny.UI UIWaitFormService.HideWaitForm(); } + /// + /// 显示等待提示窗 + /// + /// 大小 + public void ShowProcessForm(int size = 200) + { + UIProcessIndicatorFormService.ShowForm(size); + } + + /// + /// 隐藏等待提示窗 + /// + public void HideProcessForm() + { + UIProcessIndicatorFormService.HideForm(); + } + /// /// 设置等待提示窗描述文字 ///