diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index d9db3154..9078f78b 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index f00bdb6d..bcf7c767 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Charts/FLineChart.Designer.cs b/SunnyUI.Demo/Charts/FLineChart.Designer.cs index 71f90faf..1459e07f 100644 --- a/SunnyUI.Demo/Charts/FLineChart.Designer.cs +++ b/SunnyUI.Demo/Charts/FLineChart.Designer.cs @@ -104,12 +104,10 @@ this.LineChart.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.LineChart.Font = new System.Drawing.Font("微软雅黑", 12F); this.LineChart.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54))))); - this.LineChart.LegendFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.LineChart.Location = new System.Drawing.Point(30, 55); this.LineChart.MinimumSize = new System.Drawing.Size(1, 1); this.LineChart.Name = "LineChart"; this.LineChart.Size = new System.Drawing.Size(670, 430); - this.LineChart.SubFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.LineChart.TabIndex = 35; this.LineChart.Text = "uiLineChart1"; this.LineChart.PointValue += new Sunny.UI.UILineChart.OnPointValue(this.LineChart_PointValue); diff --git a/SunnyUI.Demo/Charts/FPieChart.Designer.cs b/SunnyUI.Demo/Charts/FPieChart.Designer.cs index cf817410..ed61814c 100644 --- a/SunnyUI.Demo/Charts/FPieChart.Designer.cs +++ b/SunnyUI.Demo/Charts/FPieChart.Designer.cs @@ -44,13 +44,11 @@ this.PieChart.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244))))); this.PieChart.Font = new System.Drawing.Font("微软雅黑", 12F); this.PieChart.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54))))); - this.PieChart.LegendFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.PieChart.Location = new System.Drawing.Point(30, 55); this.PieChart.MinimumSize = new System.Drawing.Size(1, 1); this.PieChart.Name = "PieChart"; this.PieChart.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; this.PieChart.Size = new System.Drawing.Size(670, 430); - this.PieChart.SubFont = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.PieChart.TabIndex = 20; this.PieChart.Text = "uiPieChart1"; // diff --git a/SunnyUI/Charts/UIBarChart.cs b/SunnyUI/Charts/UIBarChart.cs index 30f7b65b..8e9f6b86 100644 --- a/SunnyUI/Charts/UIBarChart.cs +++ b/SunnyUI/Charts/UIBarChart.cs @@ -485,7 +485,7 @@ namespace Sunny.UI } } - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font,SubTextFontSize); if (Option.XAxis.AxisLabel.Show) { @@ -575,7 +575,7 @@ namespace Sunny.UI g.DrawLine(pn, DrawOrigin.X, pos, Width - Option.Grid.Right, pos); } - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sf = g.MeasureString(line.Name, tmp); if (line.Left == UILeftAlignment.Left) @@ -602,7 +602,7 @@ namespace Sunny.UI for (int i = 0; i < Option.XAxis.Data.Count; i++) { - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); Bars[0][i].Size = g.MeasureString(Bars[0][i].Tips, tmp); } } diff --git a/SunnyUI/Charts/UIBarChartEx.cs b/SunnyUI/Charts/UIBarChartEx.cs index 36630fc0..a9680598 100644 --- a/SunnyUI/Charts/UIBarChartEx.cs +++ b/SunnyUI/Charts/UIBarChartEx.cs @@ -453,6 +453,7 @@ namespace Sunny.UI protected override void DrawSeries(Graphics g, List series) { if (series == null || series.Count == 0) return; + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); for (int i = 0; i < Bars.Count; i++) { @@ -465,13 +466,13 @@ namespace Sunny.UI { if (s.BarName.Count > 0 && j < s.BarName.Count) { - SizeF sf = g.MeasureString(s.BarName[j], SubFont); + SizeF sf = g.MeasureString(s.BarName[j], tmp); if (s.Data[j] >= 0) - g.DrawString(s.BarName[j], SubFont, ChartStyle.ForeColor, + g.DrawString(s.BarName[j], tmp, ChartStyle.ForeColor, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Bottom + 1); else - g.DrawString(s.BarName[j], SubFont, ChartStyle.ForeColor, + g.DrawString(s.BarName[j], tmp, ChartStyle.ForeColor, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Top - sf.Height); } @@ -480,16 +481,16 @@ namespace Sunny.UI if (s.ShowValue) { Font fontShow = null; - if (s.ShowValueFontSize > 0) fontShow = new Font(SubFont.Name, s.ShowValueFontSize); + if (s.ShowValueFontSize > 0) fontShow = new Font(tmp.Name, s.ShowValueFontSize); string value = s.Data[j].ToString("F" + Option.YAxis.AxisLabel.DecimalCount); - SizeF sf = g.MeasureString(value, fontShow ?? SubFont); + SizeF sf = g.MeasureString(value, fontShow ?? tmp); if (s.Data[j] < 0) - g.DrawString(value, fontShow ?? SubFont, bars[j].Color, + g.DrawString(value, fontShow ?? tmp, bars[j].Color, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Bottom + 1); else - g.DrawString(value, fontShow ?? SubFont, bars[j].Color, + g.DrawString(value, fontShow ?? tmp, bars[j].Color, bars[j].Rect.Left + bars[j].Rect.Width / 2 - sf.Width / 2, bars[j].Rect.Top - sf.Height); @@ -500,7 +501,7 @@ namespace Sunny.UI for (int i = 0; i < Option.Series.Count; i++) { - Bars[i][0].Size = g.MeasureString(Bars[i][0].Tips, SubFont); + Bars[i][0].Size = g.MeasureString(Bars[i][0].Tips, tmp); } } @@ -578,6 +579,7 @@ namespace Sunny.UI } } + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); //绘制X轴标签 if (Option.XAxis.AxisLabel.Show) { @@ -587,12 +589,12 @@ namespace Sunny.UI foreach (var data in Option.Series) { float w = DrawSize.Width * data.Data.Count * 1.0f / DataCount; - SizeF sf = g.MeasureString(data.Name, SubFont); + SizeF sf = g.MeasureString(data.Name, tmp); if (Option.XAxis.AxisLabel.Angle != 0) - g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, new PointF(start + w / 2.0f - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), + g.DrawString(data.Name, tmp, ChartStyle.ForeColor, new PointF(start + w / 2.0f - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360); else - g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); + g.DrawString(data.Name, tmp, ChartStyle.ForeColor, start + w / 2.0f - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); start += w; } } @@ -601,18 +603,18 @@ namespace Sunny.UI float start = DrawOrigin.X + DrawBarWidth / 2.0f; foreach (var data in Option.Series) { - SizeF sf = g.MeasureString(data.Name, SubFont); + SizeF sf = g.MeasureString(data.Name, tmp); if (Option.XAxis.AxisLabel.Angle != 0) - g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, new PointF(start - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), + g.DrawString(data.Name, tmp, ChartStyle.ForeColor, new PointF(start - 10, DrawOrigin.Y + Option.Grid.Bottom / 2.0f), new StringFormat() { Alignment = StringAlignment.Center }, (3600 - Option.XAxis.AxisLabel.Angle) % 360); else - g.DrawString(data.Name, SubFont, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); + g.DrawString(data.Name, tmp, ChartStyle.ForeColor, start - sf.Width / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance); start += DrawBarWidth; } } - SizeF sfName = g.MeasureString(Option.XAxis.Name, SubFont); - g.DrawString(Option.XAxis.Name, SubFont, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance + sfName.Height); + SizeF sfName = g.MeasureString(Option.XAxis.Name, tmp); + g.DrawString(Option.XAxis.Name, tmp, ChartStyle.ForeColor, DrawOrigin.X + (DrawSize.Width - sfName.Width) / 2.0f, DrawOrigin.Y + Option.XAxis.AxisTick.Length + Option.XAxis.AxisTick.Distance + sfName.Height); } //绘制Y轴刻度 @@ -659,20 +661,20 @@ namespace Sunny.UI if (Option.YAxis.AxisLabel.AutoFormat) Option.YAxis.AxisLabel.DecimalCount = YAxisDecimalCount; - + for (int i = YAxisStart; i <= YAxisEnd; i++) { string label = Option.YAxis.AxisLabel.GetLabel(i * YAxisInterval, idx); - SizeF sf = g.MeasureString(label, SubFont); + SizeF sf = g.MeasureString(label, tmp); wmax = Math.Max(wmax, sf.Width); - g.DrawString(label, SubFont, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f); + g.DrawString(label, tmp, ChartStyle.ForeColor, DrawOrigin.X - Option.YAxis.AxisTick.Length - sf.Width, start - sf.Height / 2.0f); start -= DrawBarHeight; } - SizeF sfname = g.MeasureString(Option.YAxis.Name, SubFont); + SizeF sfname = g.MeasureString(Option.YAxis.Name, tmp); int x = (int)(DrawOrigin.X - Option.YAxis.AxisTick.Length - wmax - sfname.Height); int y = (int)(Option.Grid.Top + (DrawSize.Height - sfname.Width) / 2); - g.DrawString(Option.YAxis.Name, SubFont, ChartStyle.ForeColor, new Point(x, y), + g.DrawString(Option.YAxis.Name, tmp, ChartStyle.ForeColor, new Point(x, y), new StringFormat() { Alignment = StringAlignment.Center }, 270); } } diff --git a/SunnyUI/Charts/UIChart.cs b/SunnyUI/Charts/UIChart.cs index 246d9b30..69302833 100644 --- a/SunnyUI/Charts/UIChart.cs +++ b/SunnyUI/Charts/UIChart.cs @@ -169,14 +169,29 @@ namespace Sunny.UI protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - if (tip != null && !tip.Font.Equals(legendFont)) - { - tip.Font = legendFont.DPIScaleFont(); - } - DrawOption(e.Graphics); } + [Category("SunnyUI")] + [DefaultValue(9)] + public float LegendFontSize { get; set; } = 9.0f; + + [Category("SunnyUI")] + [DefaultValue(9)] + public float SubTextFontSize { get; set; } = 9.0f; + + [Category("SunnyUI")] + [DefaultValue(9)] + public float TipsFontSize { get; set; } = 9.0f; + + protected override void OnFontChanged(EventArgs e) + { + base.OnFontChanged(e); + + if (tip != null) + tip.Font = this.DPIScaleFont(Font, TipsFontSize); + } + protected virtual void DrawOption(Graphics g) { } @@ -197,33 +212,11 @@ namespace Sunny.UI [DefaultValue(8)] public int TextInterval { get; set; } = 8; - private Font subFont = UIFontColor.SubFont; - - [DefaultValue(typeof(Font), "微软雅黑, 9pt")] - public Font SubFont - { - get => subFont; - set - { - subFont = value; - Invalidate(); - } - } - - private Font legendFont = UIFontColor.SubFont; - - [DefaultValue(typeof(Font), "微软雅黑, 9pt")] - public Font LegendFont - { - get => legendFont; - set - { - legendFont = value; - if (tip != null) tip.Font = subFont; - Invalidate(); - } - } + [Browsable(false), Obsolete("已过时,用SubTextFontSize代替")] + public Font SubFont { get; set; } + [Browsable(false), Obsolete("已过时,用LegendFontSize代替")] + public Font LegendFont { get; set; } protected void DrawTitle(Graphics g, UITitle title) { if (title == null) return; @@ -246,7 +239,7 @@ namespace Sunny.UI g.DrawString(title.Text, Font, ChartStyle.ForeColor, left, top); - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sfs = g.MeasureString(title.SubText, tmp); switch (title.Left) { @@ -273,7 +266,7 @@ namespace Sunny.UI float maxWidth = 0; float oneHeight = 0; - using Font tmp = LegendFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, LegendFontSize); foreach (var data in legend.Data) { SizeF sf = g.MeasureString(data, tmp); diff --git a/SunnyUI/Charts/UIDoughnutChart.cs b/SunnyUI/Charts/UIDoughnutChart.cs index 68e37280..4b021b18 100644 --- a/SunnyUI/Charts/UIDoughnutChart.cs +++ b/SunnyUI/Charts/UIDoughnutChart.cs @@ -142,7 +142,7 @@ namespace Sunny.UI private void DrawSeries(Graphics g, List series) { if (series == null || series.Count == 0) return; - using Font tmp = LegendFont.DPIScaleFont(); + using Font tmp = this. DPIScaleFont(Font, LegendFontSize); for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) { var pie = series[pieIndex]; diff --git a/SunnyUI/Charts/UILineChart.cs b/SunnyUI/Charts/UILineChart.cs index 5668ffbc..14812761 100644 --- a/SunnyUI/Charts/UILineChart.cs +++ b/SunnyUI/Charts/UILineChart.cs @@ -217,7 +217,7 @@ namespace Sunny.UI } if (XScale == null || YScale == null) return; - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); //X Tick if (Option.XAxis.AxisTick.Show) { @@ -534,7 +534,7 @@ namespace Sunny.UI private void DrawAxisScales(Graphics g) { if (YScale == null) return; - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); foreach (var line in Option.YAxisScaleLines) { float pos = YScale.CalcYPixel(line.Value, DrawOrigin.Y, DrawSize.Height); @@ -669,7 +669,7 @@ namespace Sunny.UI { using (Graphics g = this.CreateGraphics()) { - using Font tmp = SubFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, SubTextFontSize); SizeF sf = g.MeasureString(sb.ToString(), tmp); tip.Size = new Size((int)sf.Width + 4, (int)sf.Height + 4); } diff --git a/SunnyUI/Charts/UIPieChart.cs b/SunnyUI/Charts/UIPieChart.cs index e6ca7cf7..37ab478c 100644 --- a/SunnyUI/Charts/UIPieChart.cs +++ b/SunnyUI/Charts/UIPieChart.cs @@ -158,7 +158,7 @@ namespace Sunny.UI { var pie = series[pieIndex]; RectangleF rect = GetSeriesRect(pie); - using Font tmp = LegendFont.DPIScaleFont(); + using Font tmp = this.DPIScaleFont(Font, LegendFontSize); for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++) { Color color = ChartStyle.GetColor(azIndex); @@ -177,8 +177,8 @@ namespace Sunny.UI string name = Option.Legend != null ? Option.Legend.Data[azIndex] + " : " : ""; if (pie.Data[azIndex].Value > 0) { - string text = name + pie.Data[azIndex].Value.ToString("F0"); - SizeF sf = g.MeasureString(text, SubFont); + string text = name + pie.Data[azIndex].Value.ToString("F0"); + SizeF sf = g.MeasureString(text, tmp); PointF pf; int added = 9; if (az >= 0 && az < 90) @@ -191,7 +191,7 @@ namespace Sunny.UI pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added); if (pie.Data[azIndex].Value > 0) - g.DrawString(text, SubFont, color, pf.X, pf.Y); + g.DrawString(text, tmp, color, pf.X, pf.Y); } } } diff --git a/SunnyUI/Common/UControl.cs b/SunnyUI/Common/UControl.cs index 1a2b3a2c..a386c961 100644 --- a/SunnyUI/Common/UControl.cs +++ b/SunnyUI/Common/UControl.cs @@ -326,9 +326,37 @@ namespace Sunny.UI public static Font DPIScaleFont(this Control control, Font font) { if (UIStyles.DPIScale) - return new Font(font.FontFamily, font.Size / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet); + { + if (font.GdiCharSet == 134) + return new Font(font.FontFamily, font.Size / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet); + else + return new Font(font.FontFamily, font.Size / control.DPIScale()); + } else - return font; + { + if (font.GdiCharSet == 134) + return new Font(font.FontFamily, font.Size, font.Style, font.Unit, font.GdiCharSet); + else + return new Font(font.FontFamily, font.Size); + } + } + + public static Font DPIScaleFont(this Control control, Font font, float fontSize) + { + if (UIStyles.DPIScale) + { + if (font.GdiCharSet == 134) + return new Font(font.FontFamily, fontSize / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet); + else + return new Font(font.FontFamily, fontSize / control.DPIScale()); + } + else + { + if (font.GdiCharSet == 134) + return new Font(font.FontFamily, fontSize, font.Style, font.Unit, font.GdiCharSet); + else + return new Font(font.FontFamily, fontSize); + } } public static Font DPIScaleFont(this Font font) @@ -336,8 +364,7 @@ namespace Sunny.UI if (UIStyles.DPIScale) { using Control control = new(); - return new Font(font.FontFamily, font.Size / control.DPIScale(), - font.Style, font.Unit, font.GdiCharSet); + return control.DPIScaleFont(font); } else {