using C1.Win.C1Themes;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XCommon.Forms
{
/// <summary>
/// 对话框风格系统界面参数
/// </summary>
public class XFormStyleEventargs : System.EventArgs
{
/// <summary>
///
/// </summary>
public XFormStyleEventargs()
{
AutoStyle = C1.Win.C1Ribbon.VisualStyle.Office2007Blue;
C1ThemesAutoStyle = "";
}
/// <summary>
///
/// </summary>
/// <param name="autoStyle"></param>
public XFormStyleEventargs(C1.Win.C1Ribbon.VisualStyle autoStyle)
{
AutoStyle = autoStyle;
}
/// <summary>
///
/// </summary>
/// <param name="autoStyle"></param>
public XFormStyleEventargs(string autoStyle)
{
C1ThemesAutoStyle = autoStyle;
}
/// <summary>
///
/// </summary>
public C1.Win.C1Ribbon.VisualStyle AutoStyle { get; set; }
/// <summary>
///
/// </summary>
public string C1ThemesAutoStyle { get; set; }
}
/// <summary>
/// 对话框风格公共静态事件
/// </summary>
public static class XFormCommonStyle
{
/// <summary>
/// 皮肤控件
/// </summary>
public static C1.Win.C1Themes.C1ThemeController ThemeController { get; set; }
/// <summary>
/// 主题
/// </summary>
public static string Theme { get; set; }
/// <summary>
///
/// </summary>
static public C1.Win.C1Ribbon.VisualStyle AutoStyle { get; set; }
/// <summary>
///
/// </summary>
public static event EventHandler<XFormStyleEventargs> XFormStyleClick;
static XFormCommonStyle()
{
ThemeController = new C1.Win.C1Themes.C1ThemeController();
AutoStyle = C1.Win.C1Ribbon.VisualStyle.Office2007Blue;
}
/// <summary>
/// 皮肤变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static void OnXFormStyleClick(object sender, XFormStyleEventargs e)
{
Theme = e.C1ThemesAutoStyle;
AutoStyle = e.AutoStyle;
XFormStyleClick?.Invoke(sender, e);
}
/// <summary>
/// 设定控件及控件的子控件的皮肤
/// </summary>
/// <param name="ctl"></param>
public static void SetThemes(System.Windows.Forms.Control ctl)
{
ctl.SuspendLayout();
SetThemesLoop(ctl);
ctl.ResumeLayout();
}
static void SetThemesLoop(System.Windows.Forms.Control ctl)
{
if (!Fun.XDesignTime.Instance.IsDesignMode)
{
if (string.IsNullOrEmpty(Theme))
{
return;
}
if (ctl != null && C1ThemeController.IsObjectThemeable(ctl))
{
ThemeController.SetTheme(ctl, Theme);
ThemeController.ResetTheme(ctl);
}
if (ctl != null && ctl.Controls.Count > 0)
{
foreach (System.Windows.Forms.Control item in ctl.Controls)
{
SetThemesLoop(item);
}
return;
}
}
}
}
}
|