SunnyUI/SunnyUI/Pages/UIPage.cs

571 lines
19 KiB
C#
Raw Normal View History

2020-05-11 21:11:29 +08:00
/******************************************************************************
* SunnyUI
2021-02-20 15:45:47 +08:00
* CopyRight (C) 2012-2021 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@QQ.Com
2020-05-11 21:11:29 +08:00
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UIPage.cs
* : Form继承
* : V3.0
2020-05-11 21:11:29 +08:00
* : 2020-01-01
*
* 2020-01-01: V2.2.0
******************************************************************************/
using System;
using System.Collections.Generic;
2020-05-11 21:11:29 +08:00
using System.ComponentModel;
2020-06-05 22:42:48 +08:00
using System.Diagnostics;
2020-05-11 21:11:29 +08:00
using System.Drawing;
using System.Drawing.Design;
2020-05-11 21:11:29 +08:00
using System.Windows.Forms;
namespace Sunny.UI
{
[DefaultEvent("Initialize")]
public partial class UIPage : Form, IStyleInterface
{
2020-06-05 22:42:48 +08:00
public readonly Guid Guid = Guid.NewGuid();
private Color _rectColor = UIColor.Blue;
private ToolStripStatusLabelBorderSides _rectSides = ToolStripStatusLabelBorderSides.None;
protected UIStyle _style = UIStyle.Blue;
public UIMainFrame Frame;
2020-05-11 21:11:29 +08:00
public UIPage()
{
InitializeComponent();
base.BackColor = UIColor.LightBlue;
2020-06-05 22:42:48 +08:00
TopLevel = false;
if (this.Register()) SetStyle(UIStyles.Style);
2020-05-11 21:11:29 +08:00
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
UpdateStyles();
2020-06-05 22:42:48 +08:00
if (!IsDesignMode) base.Dock = DockStyle.Fill;
2020-05-11 21:11:29 +08:00
Version = UIGlobal.Version;
}
public void Render()
{
SetStyle(UIStyles.Style);
}
private int _symbolSize = 24;
[DefaultValue(24)]
2021-03-22 21:31:14 +08:00
[Description("字体图标大小"), Category("SunnyUI")]
public int SymbolSize
{
get => _symbolSize;
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, 64);
SymbolChange();
Invalidate();
}
}
private int _symbol;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Editor(typeof(UIImagePropertyEditor), typeof(UITypeEditor))]
[DefaultValue(0)]
2021-03-22 21:31:14 +08:00
[Description("字体图标"), Category("SunnyUI")]
public int Symbol
{
get => _symbol;
set
{
_symbol = value;
SymbolChange();
Invalidate();
}
}
2021-03-22 21:31:14 +08:00
[DefaultValue(false), Description("在Frame框架中不被关闭"), Category("SunnyUI")]
2020-06-27 16:53:32 +08:00
public bool AlwaysOpen { get; set; }
protected virtual void SymbolChange()
{
}
2021-03-22 21:31:14 +08:00
[Browsable(false)]
public Point ParentLocation { get; set; } = new Point(0, 0);
2020-05-11 21:11:29 +08:00
[DefaultValue(-1)]
2020-06-05 22:42:48 +08:00
public int PageIndex { get; set; } = -1;
[Browsable(false)]
public Guid PageGuid { get; set; } = Guid.Empty;
[Browsable(false), DefaultValue(null)]
public TabPage TabPage { get; set; } = null;
2020-06-05 22:42:48 +08:00
/// <summary>
/// 边框颜色
/// </summary>
/// <value>The color of the border style.</value>
2021-03-22 21:31:14 +08:00
[Description("边框颜色"), Category("SunnyUI")]
2020-06-05 22:42:48 +08:00
public Color RectColor
{
get => _rectColor;
set
{
_rectColor = value;
AfterSetRectColor(value);
_style = UIStyle.Custom;
Invalidate();
}
}
protected bool IsDesignMode
2020-05-11 21:11:29 +08:00
{
2020-06-05 22:42:48 +08:00
get
2020-05-11 21:11:29 +08:00
{
2020-06-05 22:42:48 +08:00
var ReturnFlag = false;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
ReturnFlag = true;
else if (Process.GetCurrentProcess().ProcessName == "devenv")
ReturnFlag = true;
return ReturnFlag;
2020-05-11 21:11:29 +08:00
}
2020-06-05 22:42:48 +08:00
}
[DefaultValue(ToolStripStatusLabelBorderSides.None)]
2021-03-22 21:31:14 +08:00
[Description("边框显示位置"), Category("SunnyUI")]
2020-06-05 22:42:48 +08:00
public ToolStripStatusLabelBorderSides RectSides
{
get => _rectSides;
set
{
_rectSides = value;
Invalidate();
}
}
/// <summary>
/// Tag字符串
/// </summary>
[DefaultValue(null)]
[Description("获取或设置包含有关控件的数据的对象字符串"), Category("SunnyUI")]
public string TagString { get; set; }
2020-06-05 22:42:48 +08:00
public string Version { get; }
/// <summary>
/// 主题样式
/// </summary>
[DefaultValue(UIStyle.Blue), Description("主题样式"), Category("SunnyUI")]
2020-06-05 22:42:48 +08:00
public UIStyle Style
{
get => _style;
set => SetStyle(value);
}
/// <summary>
/// 自定义主题风格
/// </summary>
[DefaultValue(false)]
[Description("获取或设置可以自定义主题风格"), Category("SunnyUI")]
public bool StyleCustomMode { get; set; }
2020-06-05 22:42:48 +08:00
public event EventHandler Initialize;
2020-05-11 21:11:29 +08:00
protected override void OnControlAdded(ControlEventArgs e)
{
base.OnControlAdded(e);
if (e.Control is IStyleInterface ctrl)
{
2020-05-11 21:11:29 +08:00
if (!ctrl.StyleCustomMode)
{
2020-05-11 21:11:29 +08:00
ctrl.Style = Style;
}
}
if (e.Control is Panel)
{
List<Control> controls = e.Control.GetUIStyleControls("IStyleInterface");
foreach (var control in controls)
{
if (control is IStyleInterface item)
{
if (!item.StyleCustomMode)
{
item.Style = Style;
}
}
}
}
2020-05-11 21:11:29 +08:00
}
public virtual void Init()
{
Initialize?.Invoke(this, null);
}
public virtual void Final()
{
}
public void SetStyle(UIStyle style)
{
2020-05-15 10:22:35 +08:00
this.SetChildUIStyle(style);
2020-05-11 21:11:29 +08:00
SetStyleColor(UIStyles.GetStyleColor(style));
_style = style;
UIStyleChanged?.Invoke(this, new EventArgs());
2020-05-11 21:11:29 +08:00
}
public event EventHandler UIStyleChanged;
2020-05-11 21:11:29 +08:00
public virtual void SetStyleColor(UIBaseStyle uiColor)
{
if (uiColor.IsCustom()) return;
BackColor = uiColor.PlainColor;
RectColor = uiColor.RectColor;
ForeColor = UIFontColor.Primary;
Invalidate();
}
protected virtual void AfterSetFillColor(Color color)
{
}
protected virtual void AfterSetRectColor(Color color)
{
}
protected virtual void AfterSetForeColor(Color color)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
2020-06-05 22:42:48 +08:00
if (Width <= 0 || Height <= 0) return;
2020-05-11 21:11:29 +08:00
if (RectSides != ToolStripStatusLabelBorderSides.None)
{
if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Left))
e.Graphics.DrawLine(RectColor, 0, 0, 0, Height - 1);
if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Top))
e.Graphics.DrawLine(RectColor, 0, 0, Width - 1, 0);
if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Right))
e.Graphics.DrawLine(RectColor, Width - 1, 0, Width - 1, Height - 1);
if (RectSides.GetValue(ToolStripStatusLabelBorderSides.Bottom))
e.Graphics.DrawLine(RectColor, 0, Height - 1, Width - 1, Height - 1);
}
}
protected override void OnBackColorChanged(EventArgs e)
{
base.OnBackColorChanged(e);
AfterSetFillColor(BackColor);
_style = UIStyle.Custom;
}
protected override void OnForeColorChanged(EventArgs e)
{
base.OnForeColorChanged(e);
AfterSetForeColor(ForeColor);
_style = UIStyle.Custom;
}
private void UIPage_Shown(object sender, EventArgs e)
{
//SetStyle(UIStyles.Style);
}
#region
/// <summary>
/// 显示进度提示窗
/// </summary>
/// <param name="desc">描述文字</param>
/// <param name="maximum">最大进度值</param>
public void ShowStatusForm(int maximum = 100, string desc = "系统正在处理中,请稍候...")
{
UIStatusFormService.ShowStatusForm(maximum, desc);
}
/// <summary>
/// 隐藏进度提示窗
/// </summary>
public void HideStatusForm()
{
UIStatusFormService.HideStatusForm();
}
/// <summary>
/// 设置进度提示窗步进值加1
/// </summary>
public void StatusFormStepIt()
{
UIStatusFormService.StepIt();
}
/// <summary>
/// 设置进度提示窗描述文字
/// </summary>
/// <param name="desc">描述文字</param>
public void SetStatusFormDescription(string desc)
{
UIStatusFormService.SetDescription(desc);
}
/// <summary>
/// 显示等待提示窗
/// </summary>
/// <param name="desc">描述文字</param>
public void ShowWaitForm(string desc = "系统正在处理中,请稍候...")
{
UIWaitFormService.ShowWaitForm(desc);
}
/// <summary>
/// 隐藏等待提示窗
/// </summary>
public void HideWaitForm()
{
UIWaitFormService.HideWaitForm();
}
/// <summary>
/// 设置等待提示窗描述文字
/// </summary>
/// <param name="desc">描述文字</param>
public void SetWaitFormDescription(string desc)
{
UIWaitFormService.SetDescription(desc);
}
/// <summary>
/// 正确信息提示框
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowSuccessDialog(string msg, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, UILocalize.SuccessTitle, false, UIStyle.Green, showMask);
}
/// <summary>
/// 信息提示框
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowInfoDialog(string msg, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, UILocalize.InfoTitle, false, UIStyle.Gray, showMask);
}
/// <summary>
/// 警告信息提示框
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowWarningDialog(string msg, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, UILocalize.WarningTitle, false, UIStyle.Orange, showMask);
}
/// <summary>
/// 错误信息提示框
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowErrorDialog(string msg, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, UILocalize.ErrorTitle, false, UIStyle.Red, showMask);
}
/// <summary>
/// 确认信息提示框
/// </summary>
/// <param name="msg">信息</param>
/// <param name="showMask">显示遮罩层</param>
/// <returns>结果</returns>
public bool ShowAskDialog(string msg, bool showMask = true)
{
return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, true, UIStyle.Blue, showMask);
}
/// <summary>
/// 正确信息提示框
/// </summary>
/// <param name="title">标题</param>
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowSuccessDialog(string title, string msg, UIStyle style = UIStyle.Green, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, title, false, style, showMask);
}
/// <summary>
/// 信息提示框
/// </summary>
/// <param name="title">标题</param>
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowInfoDialog(string title, string msg, UIStyle style = UIStyle.Gray, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, title, false, style, showMask);
}
/// <summary>
/// 警告信息提示框
/// </summary>
/// <param name="title">标题</param>
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowWarningDialog(string title, string msg, UIStyle style = UIStyle.Orange, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, title, false, style, showMask);
}
/// <summary>
/// 错误信息提示框
/// </summary>
/// <param name="title">标题</param>
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
public void ShowErrorDialog(string title, string msg, UIStyle style = UIStyle.Red, bool showMask = true)
{
UIMessageDialog.ShowMessageDialog(msg, title, false, style, showMask);
}
/// <summary>
/// 确认信息提示框
/// </summary>
/// <param name="title">标题</param>
/// <param name="msg">信息</param>
/// <param name="style">主题</param>
/// <param name="showMask">显示遮罩层</param>
/// <returns>结果</returns>
public bool ShowAskDialog(string title, string msg, UIStyle style = UIStyle.Blue, bool showMask = true)
{
return UIMessageDialog.ShowMessageDialog(msg, title, true, style, showMask);
}
/// <summary>
/// 显示消息
/// </summary>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowInfoTip(string text, int delay = 1000, bool floating = true)
=> UIMessageTip.Show(text, null, delay, floating);
/// <summary>
/// 显示成功消息
/// </summary>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowSuccessTip(string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowOk(text, delay, floating);
/// <summary>
/// 显示警告消息
/// </summary>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowWarningTip(string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowWarning(text, delay, floating);
/// <summary>
/// 显示出错消息
/// </summary>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowErrorTip(string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowError(text, delay, floating);
/// <summary>
/// 在指定控件附近显示消息
/// </summary>
/// <param name="controlOrItem">控件或工具栏项</param>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowInfoTip(Component controlOrItem, string text, int delay = 1000, bool floating = true)
=> UIMessageTip.Show(controlOrItem, text, null, delay, floating);
/// <summary>
/// 在指定控件附近显示良好消息
/// </summary>
/// <param name="controlOrItem">控件或工具栏项</param>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowSuccessTip(Component controlOrItem, string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowOk(controlOrItem, text, delay, floating);
/// <summary>
/// 在指定控件附近显示出错消息
/// </summary>
/// <param name="controlOrItem">控件或工具栏项</param>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowErrorTip(Component controlOrItem, string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowError(controlOrItem, text, delay, floating);
/// <summary>
/// 在指定控件附近显示警告消息
/// </summary>
/// <param name="controlOrItem">控件或工具栏项</param>
/// <param name="text">消息文本</param>
/// <param name="delay">消息停留时长(ms)。默认1秒</param>
/// <param name="floating">是否漂浮</param>
public void ShowWarningTip(Component controlOrItem, string text, int delay = 1000, bool floating = true)
=> UIMessageTip.ShowWarning(controlOrItem, text, delay, floating, false);
public void ShowInfoNotifier(string desc, bool isDialog = false, int timeout = 2000)
{
UINotifierHelper.ShowNotifier(desc, UINotifierType.INFO, UILocalize.InfoTitle, false, timeout);
}
public void ShowSuccessNotifier(string desc, bool isDialog = false, int timeout = 2000)
{
UINotifierHelper.ShowNotifier(desc, UINotifierType.OK, UILocalize.SuccessTitle, false, timeout);
}
public void ShowWarningNotifier(string desc, bool isDialog = false, int timeout = 2000)
{
UINotifierHelper.ShowNotifier(desc, UINotifierType.WARNING, UILocalize.WarningTitle, false, timeout);
}
public void ShowErrorNotifier(string desc, bool isDialog = false, int timeout = 2000)
{
UINotifierHelper.ShowNotifier(desc, UINotifierType.ERROR, UILocalize.ErrorTitle, false, timeout);
}
#endregion
2020-05-11 21:11:29 +08:00
}
}