Files

113 lines
3.7 KiB
C#

using AllBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TemuKJD.BaseForms
{
public partial class BaseMsgForm : BaseGeneralForm
{
public BaseMsgForm()
{
InitializeComponent();
this.ShowMinimizedBox = false;
this.AcceptButton = btnConfirm;
}
public static BaseMsgForm ShowInfo(string msg, string caption = "", FormLevel fl = FormLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "系统提示" : caption;
BaseMsgForm msgBox = CreateMsgForm(msg, fl, title);
msgBox.picTip.Image = global::TemuKJD.Properties.Resources.BaseMsgInfo;
if (MainForm.instance != null && MainForm.instance.InvokeRequired)
MainForm.instance.Invoke(new Action(() =>
{
msgBox.ShowDialog();
}));
else
msgBox.ShowDialog();
return msgBox;
}
private static BaseMsgForm CreateMsgForm(string msg, FormLevel fl, string title)
{
BaseMsgForm msgBox = new BaseMsgForm { Text = title, lblMsg = { Text = msg }, TitleText = title };
if (fl.Equals(FormLevel.LARGE))
{
msgBox.Width = (int)FormLevel.LARGE;
msgBox.Height = 280;
}
msgBox.btnConfirm.Location = msgBox.btnCancel.Location; // 把确认按钮移到取消按钮上面
msgBox.btnCancel.Visible = false;
return msgBox;
}
public static BaseMsgForm ShowError(string msg, string caption = "", FormLevel fl = FormLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "系统错误" : caption;
BaseMsgForm msgBox = CreateMsgForm(msg, fl, title);
msgBox.picTip.Image = global::TemuKJD.Properties.Resources.BaseMsgErr;
if (MainForm.instance != null && MainForm.instance.InvokeRequired)
MainForm.instance.Invoke(new Action(() =>
{
msgBox.ShowDialog();
}));
else
msgBox.ShowDialog();
return msgBox;
}
public static BaseMsgForm ShowConfirm(string msg, string caption = "", FormLevel fl = FormLevel.MEDIUM, bool isTopMost = false)
{
string title = string.IsNullOrEmpty(caption) ? "系统提示确认" : caption;
BaseMsgForm msgBox = new BaseMsgForm
{
Text = title,
lblMsg = { Text = msg },
TitleText = title,
picTip = { Image = global::TemuKJD.Properties.Resources.BaseMsgQue },
TopMost = isTopMost
};
if (fl.Equals(FormLevel.LARGE))
{
msgBox.Width = (int)FormLevel.LARGE;
msgBox.Height = 280;
}
if (MainForm.instance != null && MainForm.instance.InvokeRequired)
MainForm.instance.Invoke(new Action(() =>
{
msgBox.ShowDialog();
}));
else
msgBox.ShowDialog();
return msgBox;
}
private void PnlConfirm_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void PnlCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
public enum FormLevel
{
SMALL,
MEDIUM,
LARGE = 500
}
}