自定义消息框

消息框自定义

using PipeSystem.UI.Froms.Dialog;
using System;
using System.Threading;

namespace PipeSystem.UI.Froms
{
public class MessageDialog
{
/// <summary>
/// 单例模式
/// </summary>
public static MessageDialog Instance
{
get
{
if (MessageDialog._instance == null)
{
lock (syncLock)
{
if (MessageDialog._instance == null)
{
MessageDialog._instance = new MessageDialog();
}
}
}
return MessageDialog._instance;
}
}

private static MessageDialog _instance;
private static readonly Object syncLock = new Object();
private Thread waitThread;
private static FrmMessageDialog waitForm;
/// <summary>
/// 显示等待窗体
/// </summary>
public static void Show(string Title,string Content)
{
MessageDialog.Instance._CreateForm(Title,Content);
}

/// <summary>
/// 关闭等待窗体
/// </summary>
public static void Close()
{
Thread.Sleep(100);
MessageDialog.Instance._CloseForm();
}

/// <summary>
/// 创建等待窗体
/// </summary>
public void _CreateForm(string Title,string Content)
{
waitForm = null;
this._ShowWaitForm(Title,Content);
}

private void _ShowWaitForm(string Title,string Content)
{
try
{
waitForm = new FrmMessageDialog(Title,Content);//自定义窗体传值
waitForm.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
waitForm.Topmost = true;
waitForm.ShowDialog();
}
catch (ThreadAbortException e)
{
waitForm.Close();
}
}

/// <summary>
/// 关闭窗体
/// </summary>
private void _CloseForm()
{
if (waitThread != null)
{
waitForm.Close();
}
}


}
}

调用方式

MessageDialog.Show("温馨提示", "导出成功!");
return;

 

 

posted @ 2020-12-11 17:08  林新i  阅读(106)  评论(0编辑  收藏  举报