// ***********************************************************************
// Assembly : Construction
// Author : flythink
// Created : 05-21-2020
//
// Last Modified By : flythink
// Last Modified On : 09-01-2020
// ***********************************************************************
//
// Copyright (c) jindongfang. All rights reserved.
//
//
// ***********************************************************************
namespace WellWorkDataUI
{
using DevExpress.XtraSplashScreen;
using DevExpress.XtraWaitForm;
using System;
using System.Windows.Forms;
using static WellWorkDataUI.SplashHelper;
///
/// Class DlgWait.
/// Implements the
///
///
public partial class DlgWait : WaitForm
{
private static DlgWait instance;
private static SplashScreenManager splashScreenManager;
private static string description = string.Empty;
///
/// Gets or sets a value indicating whether [enable close].
///
public static bool EnableClose { get; set; } = true;
///
/// Initializes a new instance of the class.
///
public DlgWait()
{
this.InitializeComponent();
this.progressPanel1.AutoHeight = true;
this.ShowOnTopMode = ShowFormOnTopMode.ObsoleteAboveParent;
}
///
/// Enum WaitFormCommand
///
public enum WaitFormCommand
{
///
/// The message box
///
MessageBox,
ShowOnTopMode,
}
///
/// 单例
///
/// The instance.
public static DlgWait Instance
{
get
{
if (instance == null)
{
instance = new DlgWait();
}
return instance;
}
}
///
/// Shows the window.
///
/// The parent.
/// The action.
/// IAsyncResult.
public static IAsyncResult ShowWindow(Control parent, Action action)
{
IAsyncResult result = parent.BeginInvoke(new Action(() =>
{
if (splashScreenManager == null)
{
splashScreenManager = new SplashScreenManager(parent.FindForm(), typeof(global::WellWorkDataUI.DlgWait), true, false);
splashScreenManager.ShowWaitForm();
splashScreenManager.SetWaitFormDescription(description);
}
// EnableClose = false;
action();
// splashScreenManager.CloseWaitForm();
// splashScreenManager = null;
// EnableClose = true;
}));
return result;
}
///
/// Closes the window.
///
public static void CloseWindow()
{
if (splashScreenManager == null || EnableClose == false)
{
return;
}
if (splashScreenManager.IsSplashFormVisible)
{
description = string.Empty;
splashScreenManager.CloseWaitForm();
splashScreenManager = null;
}
}
///
/// Sets the wait caption.
///
/// The MSG.
public static void SetWaitCaption(string msg)
{
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormCaption(msg);
}
///
/// Sets the wait description.
///
/// The MSG.
public static void SetWaitDescription(string msg)
{
description = msg;
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormDescription(msg);
}
///
/// Appends the description.
///
/// The MSG.
public static void AppendDescription(string msg)
{
description += msg;
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormDescription(description);
}
///
/// 移除提示信息
///
/// 信息内容
public static void RemoveDescription(string msg)
{
if (splashScreenManager == null)
{
return;
}
description = description.Replace(msg, string.Empty);
splashScreenManager.SetWaitFormDescription(description);
}
///
/// When overridden, the method allows you to process commands received from a via the method.
///
/// An enumeration value that identifies the received command.
/// The received command's parameter.
public override void ProcessCommand(Enum cmd, object arg)
{
if (cmd.Equals(WaitFormCommand.MessageBox) && arg is MessageBoxData data)
{
data.Result = MessageBox.Show(this, data.Text, data.Title, data.Buttons, data.Icon);
return;
}
else if (cmd.Equals(this.ShowOnTopMode))
{
this.ShowOnTopMode = (ShowFormOnTopMode)arg;
}
base.ProcessCommand(cmd, arg);
}
///
/// Sets the 's caption to the specified value.
///
/// A string that is the new value for the 's caption.
public override void SetCaption(string caption)
{
base.SetCaption(caption);
this.progressPanel1.Caption = caption;
}
///
/// Sets the 's description to the specified value.
///
/// A string that is the new value for the 's description.
public override void SetDescription(string description)
{
base.SetDescription(description);
this.progressPanel1.Description = description;
}
}
}