// ***********************************************************************
// Assembly : Construction
// Author : flythink
// Created : 06-03-2020
//
// Last Modified By : flythink
// Last Modified On : 09-01-2020
// ***********************************************************************
//
// Copyright (c) jindongfang. All rights reserved.
//
//
// ***********************************************************************
///
/// The NewLook namespace.
///
namespace WellWorkDataUI
{
using DevExpress.XtraSplashScreen;
using System;
using System.Windows.Forms;
///
/// using自动关闭Splash
///
public class SplashHelper : IDisposable
{
///
/// The pool
///
private static ObjectPool pool = new ObjectPool(() => new SplashHelper());
///
/// Prevents a default instance of the class from being created.
///
private SplashHelper()
{
}
///
/// Creates this instance.
///
/// SplashHelper.
public static SplashHelper Create()
{
SplashHelper item = pool.Get();
item.OpenSplash();
return item;
}
///
/// Sets the wait form caption.
///
/// The captain.
public static void SetCaption(string captain)
{
if (SplashScreenManager.Default == null)
{
return;
}
SplashScreenManager.Default.SetWaitFormCaption(captain);
}
///
/// 自动创建
///
/// 表头
public static void SetCaptionM(string captain)
{
try
{
if (SplashScreenManager.Default == null)
{
Create();
}
SplashScreenManager.Default.SetWaitFormCaption(captain);
}
catch (Exception) { }
}
///
/// Sets the wait form description.
///
/// The description.
public static void SetDescription(string description)
{
if (SplashScreenManager.Default == null)
{
return;
}
SplashScreenManager.Default.SetWaitFormDescription(description);
}
public static void SetDescriptionM(string captain, string description)
{
try
{
if (SplashScreenManager.Default == null)
{
Create();
}
if (!string.IsNullOrEmpty(captain))
{
SplashScreenManager.Default.SetWaitFormCaption(captain);
}
SplashScreenManager.Default.SetWaitFormDescription(description);
}
catch (Exception) { }
}
///
/// Shows the message box.
///
/// The owner.
/// The text.
/// The title.
/// The buttons.
/// The icon.
/// DialogResult.
public static DialogResult ShowMessageBox(IWin32Window owner, string text, string title = "", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.Information)
{
if (SplashScreenManager.Default == null)
{
return MessageBox.Show(owner, text, title, buttons, icon);
}
else
{
MessageBoxData data = new MessageBoxData
{
Text = text,
Title = title,
Buttons = buttons,
Icon = icon,
};
SplashScreenManager.Default.SendCommand(DlgWait.WaitFormCommand.MessageBox, data);
return data.Result;
}
}
///
/// Provides objects that represent the root keys in the Windows registry, and methods to access key/value pairs.
///
public void Dispose()
{
this.CloseSplash();
pool.Return(this);
}
///
/// Closes the splash.
///
private void CloseSplash()
{
SplashScreenManager.CloseForm(false, true);
}
///
/// Opens the splash.
///
private void OpenSplash()
{
this.CloseSplash();
SplashScreenManager.ShowForm(Form.ActiveForm, typeof(DlgWait));
}
///
/// Class MessageBoxData.
///
internal class MessageBoxData
{
///
/// Gets or sets the text.
///
public string Text { get; set; }
///
/// Gets or sets the title.
///
public string Title { get; set; }
///
/// Gets or sets the buttons.
///
public MessageBoxButtons Buttons { get; set; }
///
/// Gets or sets the icon.
///
public MessageBoxIcon Icon { get; set; }
///
/// Gets or sets the result.
///
public DialogResult Result { get; set; } = DialogResult.None;
}
}
}