142 lines
4.5 KiB
C#
142 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Work.BaseForms
|
|
{
|
|
public partial class BaseMsgForm : BaseGeneralForm
|
|
{
|
|
public BaseMsgForm()
|
|
{
|
|
InitializeComponent();
|
|
this.Minimized = this.MinimizeBox = false;
|
|
this.AcceptButton = pnlConfirm;
|
|
SetWindowRegion();
|
|
}
|
|
#region 设置窗体圆角
|
|
/// <summary>
|
|
/// 设置窗体的Region
|
|
/// </summary>
|
|
public void SetWindowRegion()
|
|
{
|
|
//GraphicsPath FormPath;
|
|
//Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
|
|
//FormPath = GetRoundedRectPath(rect, 6);
|
|
//this.Region = new Region(FormPath);
|
|
|
|
Helper.WindowStyle.SetFormRoundRectRgn(this, 6);
|
|
Helper.WindowStyle.SetFormRoundRectRgn(this.panel2, 5);
|
|
}
|
|
/// <summary>
|
|
/// 绘制圆角路径
|
|
/// </summary>
|
|
/// <param name="rect"></param>
|
|
/// <param name="radius"></param>
|
|
/// <returns></returns>
|
|
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
|
|
{
|
|
int diameter = radius;
|
|
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
|
|
GraphicsPath path = new GraphicsPath();
|
|
|
|
// 左上角
|
|
path.AddArc(arcRect, 180, 90);
|
|
|
|
// 右上角
|
|
arcRect.X = rect.Right - diameter;
|
|
path.AddArc(arcRect, 270, 90);
|
|
|
|
// 右下角
|
|
arcRect.Y = rect.Bottom - diameter;
|
|
path.AddArc(arcRect, 0, 90);
|
|
|
|
// 左下角
|
|
arcRect.X = rect.Left;
|
|
path.AddArc(arcRect, 90, 90);
|
|
path.CloseFigure();//闭合曲线
|
|
return path;
|
|
}
|
|
|
|
#endregion
|
|
|
|
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::Work.Properties.Resources.BaseMsgInfo;
|
|
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.pnlConfirm.Location = msgBox.pnlCancel.Location; // 把确认按钮移到取消按钮上面
|
|
msgBox.pnlCancel.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::Work.Properties.Resources.BaseMsgErr;
|
|
msgBox.ShowDialog();
|
|
return msgBox;
|
|
}
|
|
|
|
public static BaseMsgForm ShowConfirm(string msg, string caption = "", FormLevel fl = FormLevel.MEDIUM)
|
|
{
|
|
string title = string.IsNullOrEmpty(caption) ? "系统提示确认" : caption;
|
|
BaseMsgForm msgBox = new BaseMsgForm
|
|
{
|
|
Text = title,
|
|
lblMsg = { Text = msg },
|
|
TitleText = title,
|
|
picTip = { Image = global::Work.Properties.Resources.BaseMsgQue }
|
|
};
|
|
if (fl.Equals(FormLevel.LARGE))
|
|
{
|
|
msgBox.Width = (int)FormLevel.LARGE;
|
|
}
|
|
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;
|
|
}
|
|
|
|
private void lblMsg_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public enum FormLevel
|
|
{
|
|
SMALL,
|
|
MEDIUM,
|
|
LARGE = 500
|
|
}
|
|
|
|
}
|