You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
6.0 KiB
C#

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