Files
KJD_WebService/TEMUKJD/BaseForms/BaseForm.cs
T

183 lines
7.5 KiB
C#

using AllBase;
using AllBase.Helper;
using DevComponents.DotNetBar;
using NaiBa.Util.Extension;
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;
using TemuKJD.UserControls;
namespace TemuKJD.BaseForms
{
public partial class BaseForm : Form
{
public bool IsSetFontScaleNone { get; set; } = true;
public float FormDpi
{
get
{
return dpi;
}
}
private float dpi = 96;
public BaseForm()
{
InitializeComponent();
}
private void BaseForm_Load(object sender, EventArgs e)
{
setSkinColor(this);
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpi = graphics.DpiX;
// 或者使用 graphics.DpiY 获取垂直方向的DPI
// float dpi = graphics.DpiY;
// Console.WriteLine("Screen DPI: " + dpi); // winform程序会闪退
if (IsSetFontScaleNone)
SetFont(this, dpi);
}
}
public void SetFont(Control control, float dpi)
{
foreach (Control c in control.Controls)
{
SetFont(c, dpi);
Font of = c.Font;
Font nf = new Font(of.FontFamily, (of.Size * 96.0 / dpi).ParseToFloat(), of.Style, of.Unit, of.GdiCharSet, of.Bold);
c.Font = nf;
if (c is DevComponents.DotNetBar.PanelEx)
{
var pEx = (c as DevComponents.DotNetBar.PanelEx);
if (pEx.Style.Font != null)
{
Font osf = pEx.Style.Font;
Font nsf = new Font(osf.FontFamily, (osf.Size * 96.0 / dpi).ParseToFloat(), osf.Style, osf.Unit, osf.GdiCharSet, osf.Bold);
pEx.Style.Font = nsf;
}
if (pEx.StyleMouseOver.Font != null)
{
Font oof = pEx.StyleMouseOver.Font;
Font nof = new Font(oof.FontFamily, (oof.Size * 96.0 / dpi).ParseToFloat(), oof.Style, oof.Unit, oof.GdiCharSet, oof.Bold);
pEx.StyleMouseOver.Font = nof;
}
if (pEx.StyleMouseDown.Font != null)
{
Font odf = pEx.StyleMouseDown.Font;
Font ndf = new Font(odf.FontFamily, (odf.Size * 96.0 / dpi).ParseToFloat(), odf.Style, odf.Unit, odf.GdiCharSet, odf.Bold);
pEx.StyleMouseDown.Font = ndf;
}
}
if (c is UserComponent.UcTreeView)
{
var tree = c as UserComponent.UcTreeView;
Font ogf = tree.GroupFont;
Font ngf = new Font(ogf.FontFamily, (ogf.Size * 96.0 / dpi).ParseToFloat(), ogf.Style, ogf.Unit, ogf.GdiCharSet, ogf.Bold);
tree.GroupFont = ngf;
}
if (c.Name == "pnlSA")
{
}
}
}
public void setSkinColor(Control control)
{
foreach (Control c in control.Controls)
{
setSkinColor(c);
// pdd皮肤颜色
if (BaseClass.MainPath == "29pdd" || BaseClass.MainPath == "29wx")
{
if (c is Panel && c.BackColor == GlobalConfig.DefaultMainColor)
{
c.BackColor = GlobalConfig.MainColor;
}
else if (c is PanelEx && c.Name.StartsWith("btn"))
{
var pnl = c as PanelEx;
if (pnl.Style.BackColor1.Color == GlobalConfig.DefaultMainColor)
{
pnl.Style.BackColor1.Color = GlobalConfig.MainColor;
pnl.Style.BackColor2.Color = GlobalConfig.MainColor;
pnl.StyleMouseOver.BackColor1.Color = GlobalConfig.BorderColor;
pnl.StyleMouseOver.BackColor2.Color = GlobalConfig.BorderColor;
}
else if (pnl.Style.BackColor1.Color == GlobalConfig.DefaultMainColorLight || pnl.Style.BorderColor.Color == GlobalConfig.DefaultMainColor)
{
pnl.Style.BorderColor.Color = GlobalConfig.MainColor;
pnl.Style.BackColor1.Color = GlobalConfig.MainColorLight;
pnl.Style.BackColor2.Color = GlobalConfig.MainColorLight;
pnl.Style.ForeColor.Color = GlobalConfig.BorderColor;
pnl.StyleMouseOver.BackColor1.Color = GlobalConfig.BorderColor;
pnl.StyleMouseOver.BackColor2.Color = GlobalConfig.BorderColor;
}
}
else if (c is ButtonEx)
{
c.BackColor = GlobalConfig.MainColor;
}
else if (c is SplitContainer && c.BackColor == GlobalConfig.DefaultMainColor)
{
c.BackColor = GlobalConfig.MainColor;
}
else if (c is UserComponent.UcTreeView)
{
var tv = c as UserComponent.UcTreeView;
tv.ChildNodeSelectedBgColor = GlobalConfig.MainColor;
}
else if (c is UserComponent.UcGroupBoxEx && (c as UserComponent.UcGroupBoxEx).BorderColor == GlobalConfig.DefaultMainColor)
{
var gb = c as UserComponent.UcGroupBoxEx;
gb.BorderColor = GlobalConfig.MainColor;
}
else if (c is UserComponent.DataGridViewEx)
{
var dgv = c as UserComponent.DataGridViewEx;
dgv.BorderColor = GlobalConfig.MainColor;
dgv.DefaultCellStyle.SelectionBackColor = GlobalConfig.MainColor;
dgv.CheckBoxRowBoxCheckColor = GlobalConfig.MainColor;
dgv.CheckBoxRowBoxBorderColor = GlobalConfig.BorderColor;
}
else if (c is UserComponent.UcCheckBox)
{
var chk = c as UserComponent.UcCheckBox;
chk.CheckBoxCheckColor = GlobalConfig.MainColor;
chk.CheckBoxBorderColor = GlobalConfig.BorderColor;
}
else if (c is UserComponent.UcTabControl)
{
var tc = c as UserComponent.UcTabControl;
tc.TabSelectColor = GlobalConfig.MainColor;
tc.TabSelectTextColor = GlobalConfig.MainColor;
}
else if (c is UcTabControlMetro)
{
var tc = c as UcTabControlMetro;
tc.BorderColor = GlobalConfig.BorderColor;
tc.TabSelectColor = GlobalConfig.MainColor;
tc.TabSelectTextColor = GlobalConfig.MainColor;
}
}
}
}
}
}