diff --git a/Bin/SunnyUI.dll b/Bin/SunnyUI.dll index 9d65df20..8649e2f2 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/Bin/SunnyUI.pdb b/Bin/SunnyUI.pdb index 2b119045..42d73e2e 100644 Binary files a/Bin/SunnyUI.pdb and b/Bin/SunnyUI.pdb differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe index db55c592..f8d78d1c 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.Demo.exe and b/SunnyUI.Demo/Bin/SunnyUI.Demo.exe differ diff --git a/SunnyUI.Demo/Bin/SunnyUI.dll b/SunnyUI.Demo/Bin/SunnyUI.dll index 9d65df20..8649e2f2 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.dll and b/SunnyUI.Demo/Bin/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Charts/FPieChart.cs b/SunnyUI.Demo/Charts/FPieChart.cs index 51976313..00a90162 100644 --- a/SunnyUI.Demo/Charts/FPieChart.cs +++ b/SunnyUI.Demo/Charts/FPieChart.cs @@ -32,6 +32,9 @@ option.Title.SubText = "Star"; option.Title.Left = UILeftAlignment.Center; + //设置ToolTip + option.ToolTip = new UIToolTip(); + //设置Legend option.Legend = new UILegend(); option.Legend.Orient = Orient.Vertical; diff --git a/SunnyUI.Demo/Controls/FCombobox.Designer.cs b/SunnyUI.Demo/Controls/FCombobox.Designer.cs index 3a42cf04..d4dc6092 100644 --- a/SunnyUI.Demo/Controls/FCombobox.Designer.cs +++ b/SunnyUI.Demo/Controls/FCombobox.Designer.cs @@ -69,6 +69,7 @@ // // uiDatetimePicker1 // + this.uiDatetimePicker1.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList; this.uiDatetimePicker1.FillColor = System.Drawing.Color.White; this.uiDatetimePicker1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiDatetimePicker1.Location = new System.Drawing.Point(388, 136); diff --git a/SunnyUI/Charts/UIChart.cs b/SunnyUI/Charts/UIChart.cs index 9aee077a..0cea7896 100644 --- a/SunnyUI/Charts/UIChart.cs +++ b/SunnyUI/Charts/UIChart.cs @@ -15,8 +15,47 @@ namespace Sunny.UI foreColor = UIChartStyles.Plain.ForeColor; Width = 400; Height = 300; + + tip.Parent = this; + tip.Height = 32; + tip.Width = 200; + tip.Left = 1; + tip.Top = 1; + tip.StyleCustomMode = true; + tip.Style = UIStyle.Custom; + tip.Font = UIFontColor.SubFont; + tip.RadiusSides = UICornerRadiusSides.None; + tip.Visible = false; + + tip.FillColor = UIChartStyles.Plain.BackColor; + tip.RectColor = UIChartStyles.Plain.ForeColor; + tip.ForeColor = UIChartStyles.Plain.ForeColor; + tip.Visible = false; + tip.MouseEnter += Tip_MouseEnter; } + private void Tip_MouseEnter(object sender, System.EventArgs e) + { + tip.Visible = false; + } + + private int decimalNumber; + + [DefaultValue(0),Description("显示数据格式化小数点后位数")] + public int DecimalNumber + { + get => decimalNumber; + set + { + if (decimalNumber != value) + { + decimalNumber = value; + Invalidate(); + } + } + } + + protected readonly UITransparentPanel tip = new UITransparentPanel(); private UIChartStyleType chartStyleType = UIChartStyleType.Plain; [DefaultValue(UIChartStyleType.Plain)] @@ -32,6 +71,10 @@ namespace Sunny.UI foreColor = ChartStyle.ForeColor; } + tip.FillColor = ChartStyle.BackColor; + tip.RectColor = ChartStyle.ForeColor; + tip.ForeColor = ChartStyle.ForeColor; + Invalidate(); } } @@ -81,6 +124,11 @@ namespace Sunny.UI public void SetOption(UIOption option) { Option = option; + CalcData(option); + } + + protected virtual void CalcData(UIOption o) + { } protected UIOption emptyOption; @@ -90,7 +138,10 @@ namespace Sunny.UI get { if (emptyOption == null) + { CreateEmptyOption(); + CalcData(emptyOption); + } return emptyOption; } @@ -112,7 +163,7 @@ namespace Sunny.UI { if (o == null) return; if (o.Title != null) DrawTitle(g, o.Title); - if (o.Series.Count > 0) DrawSeries(g, o.Series); + if (o.Series.Count > 0) DrawSeries(g,o, o.Series); if (o.Legend != null) DrawLegend(g, o.Legend); } @@ -120,7 +171,7 @@ namespace Sunny.UI { } - protected virtual void DrawSeries(Graphics g, List series) + protected virtual void DrawSeries(Graphics g,UIOption o, List series) { } diff --git a/SunnyUI/Charts/UIOption.cs b/SunnyUI/Charts/UIOption.cs index 9250929e..9120565f 100644 --- a/SunnyUI/Charts/UIOption.cs +++ b/SunnyUI/Charts/UIOption.cs @@ -12,6 +12,8 @@ namespace Sunny.UI public UILegend Legend; + public UIToolTip ToolTip; + public void AddSeries(UISeries series) { Series.Add(series); @@ -30,6 +32,11 @@ namespace Sunny.UI public int SeriesCount => Series.Count; } + public class UIToolTip + { + public string formatter { get; set; } = "{0}"+'\n'+"{1} : {2:f0} ({3:f2}%)"; + } + public class UILegend { public UILeftAlignment Left { get; set; } = UILeftAlignment.Center; diff --git a/SunnyUI/Charts/UIPieChart.cs b/SunnyUI/Charts/UIPieChart.cs index c76f7ba9..021da6ef 100644 --- a/SunnyUI/Charts/UIPieChart.cs +++ b/SunnyUI/Charts/UIPieChart.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; -using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Sunny.UI @@ -11,56 +10,6 @@ namespace Sunny.UI [ToolboxItem(true)] public sealed class UIPieChart : UIChart { - public UIPieChart() - { - tip.Parent = this; - tip.Height = 32; - tip.Width = 200; - tip.Left = 1; - tip.Top = 1; - tip.BackColor = Color.FromArgb(80, Color.Black); - tip.Font = UIFontColor.SubFont; - tip.Style = UIStyle.Custom; - tip.StyleCustomMode = true; - tip.FillColor = Color.Black; - tip.RectColor = Color.FromArgb(100, Color.Black); - tip.Visible = false; - } - - private readonly UIAlphaPanel tip = new UIAlphaPanel(); - - public class UIAlphaPanel : UIPanel - { - private int _opacity = 50; - - [Bindable(true), Category("Custom"), DefaultValue(125), Description("背景的透明度. 有效值0-255")] - public int Opacity - { - get { return _opacity; } - set - { - if (value > 255) value = 255; - else if (value < 0) value = 0; - _opacity = value; - this.Invalidate(); - } - } - - protected override CreateParams CreateParams - { - get - { - CreateParams cp = base.CreateParams; - cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT - return cp; - } - } - - protected override void OnPaintFill(Graphics g, GraphicsPath path) - { - } - } - protected override void CreateEmptyOption() { if (emptyOption != null) return; @@ -123,19 +72,16 @@ namespace Sunny.UI g.DrawString(title.SubText, subFont, ChartStyle.ForeColor, left, top); } - protected override void DrawSeries(Graphics g, List series) + protected override void CalcData(UIOption o) { - if (series == null || series.Count == 0) return; + Angles.Clear(); + if (o == null || o.Series == null || o.Series.Count == 0) return; - for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) + for (int pieIndex = 0; pieIndex < o.Series.Count; pieIndex++) { - var pie = series[pieIndex]; - if (!Angles.ContainsKey(pieIndex)) - { - Angles.TryAdd(pieIndex, new ConcurrentDictionary()); - } + var pie = o.Series[pieIndex]; + Angles.TryAdd(pieIndex, new ConcurrentDictionary()); - RectangleF rect = GetSeriesRect(pie); double all = 0; foreach (var data in pie.Data) { @@ -147,17 +93,41 @@ namespace Sunny.UI for (int i = 0; i < pie.Data.Count; i++) { float angle = (float)(pie.Data[i].Value * 360.0f / all); - string text = pie.Data[i].Name + ": " + pie.Data[i].Value.ToString("F0"); - SizeF sf = g.MeasureString(text, legendFont); - Angles[pieIndex].AddOrUpdate(i, new Angle(start, angle, text, sf)); + float percent = (float)(pie.Data[i].Value * 100.0f / all); + string text = ""; + if (o.ToolTip != null) + { + try + { + text = string.Format(o.ToolTip.formatter, pie.Name, pie.Data[i].Name, pie.Data[i].Value, percent); + } + catch + { + text = pie.Data[i].Name + " : " + pie.Data[i].Value.ToString("F" + DecimalNumber) + "(" + percent.ToString("F2") + "%)"; + if (pie.Name.IsValid()) text = pie.Name + '\n' + text; + } + } + + Angles[pieIndex].AddOrUpdate(i, new Angle(start, angle, text)); start += angle; } + } + } + protected override void DrawSeries(Graphics g, UIOption o, List series) + { + if (series == null || series.Count == 0) return; + + for (int pieIndex = 0; pieIndex < series.Count; pieIndex++) + { + var pie = series[pieIndex]; + RectangleF rect = GetSeriesRect(pie); for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++) { Color color = ChartStyle.SeriesColor[azIndex % ChartStyle.ColorCount]; RectangleF rectx = new RectangleF(rect.X - 10, rect.Y - 10, rect.Width + 20, rect.Width + 20); g.FillPie(color, (ActivePieIndex == pieIndex && ActiveAzIndex == azIndex) ? rectx : rect, Angles[pieIndex][azIndex].Start - 90, Angles[pieIndex][azIndex].Sweep); + Angles[pieIndex][azIndex].Size = g.MeasureString(Angles[pieIndex][azIndex].Text, legendFont); } } } @@ -257,11 +227,34 @@ namespace Sunny.UI if (az >= Angles[pieIndex][azIndex].Start && az <= Angles[pieIndex][azIndex].Start + Angles[pieIndex][azIndex].Sweep) { SetPieAndAzIndex(pieIndex, azIndex); - tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4); - tip.Text = Angles[pieIndex][azIndex].Text; - tip.Left = e.Location.X + 15; - tip.Top = e.Location.Y + 20; - tip.Visible = true; + if (tip.Text != Angles[pieIndex][azIndex].Text) + { + tip.Text = Angles[pieIndex][azIndex].Text; + tip.Size = new Size((int)Angles[pieIndex][azIndex].Size.Width + 4, (int)Angles[pieIndex][azIndex].Size.Height + 4); + } + + if (az >= 0 && az < 90) + { + tip.Top = e.Location.Y + 20; + tip.Left = e.Location.X - tip.Width; + } + else if (az >= 90 && az < 180) + { + tip.Left = e.Location.X - tip.Width; + tip.Top = e.Location.Y - tip.Height - 2; + } + else if (az >= 180 && az < 270) + { + tip.Left = e.Location.X ; + tip.Top = e.Location.Y - tip.Height - 2; + } + else if (az >= 270 && az < 360) + { + tip.Left = e.Location.X + 15; + tip.Top = e.Location.Y + 20; + } + + if (!tip.Visible) tip.Visible = Angles[pieIndex][azIndex].Text.IsValid(); return; } } @@ -294,22 +287,21 @@ namespace Sunny.UI return new RectangleF(left - halfRadius, top - halfRadius, halfRadius * 2, halfRadius * 2); } - public struct Angle + public class Angle { public float Start { get; set; } public float Sweep { get; set; } - public Angle(float start, float sweep, string text, SizeF size) + public Angle(float start, float sweep, string text) { Start = start; Sweep = sweep; Text = text; - Size = size; } - public SizeF Size { get; set; } - public string Text { get; set; } + + public SizeF Size { get; set; } } } } \ No newline at end of file diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index 1906c1b7..c4d7289b 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -263,7 +263,7 @@ namespace Sunny.UI protected override void WndProc(ref Message m) { base.WndProc(ref m); - + if (IsDisposed || Disposing) return; if (ShowRect) { if (m.Msg == 0xf || m.Msg == 0x133) diff --git a/SunnyUI/Controls/UIGrid.cs b/SunnyUI/Controls/UIGrid.cs index 40174041..42c89bb9 100644 --- a/SunnyUI/Controls/UIGrid.cs +++ b/SunnyUI/Controls/UIGrid.cs @@ -1018,6 +1018,7 @@ namespace Sunny.UI protected override void WndProc(ref Message m) { base.WndProc(ref m); + if (IsDisposed || Disposing) return; ScrollBarInfo.ShowScrollBar(Handle, 0, false);//0:horizontal,1:vertical,3:both } } diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index c4f43a11..0d8e2dce 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -339,13 +339,6 @@ namespace Sunny.UI set => SetStyle(value); } - // protected override void WndProc(ref Message m) - // { - // base.WndProc(ref m); - // //隐藏滚动条 - // ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both - // } - protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); diff --git a/SunnyUI/Controls/UINavMenu.cs b/SunnyUI/Controls/UINavMenu.cs index b8e8ff19..493a2f35 100644 --- a/SunnyUI/Controls/UINavMenu.cs +++ b/SunnyUI/Controls/UINavMenu.cs @@ -60,7 +60,7 @@ namespace Sunny.UI Bar.Style = UIStyle.Custom; Bar.StyleCustomMode = true; Bar.FillColor = fillColor; - + Bar.ForeColor = Color.Silver; Bar.HoverColor = Color.Silver; Bar.PressColor = Color.Silver; @@ -609,8 +609,8 @@ namespace Sunny.UI protected override void WndProc(ref Message m) { base.WndProc(ref m); - //隐藏滚动条 - ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both + if (IsDisposed || Disposing) return; + ScrollBarInfo.ShowScrollBar(Handle, 3, false); } public TreeNode CreateNode(string text, int pageIndex) diff --git a/SunnyUI/Controls/UITransparentPanel.cs b/SunnyUI/Controls/UITransparentPanel.cs new file mode 100644 index 00000000..d7c9b1a1 --- /dev/null +++ b/SunnyUI/Controls/UITransparentPanel.cs @@ -0,0 +1,46 @@ +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace Sunny.UI +{ + [ToolboxItem(false)] + public class UITransparentPanel : UIPanel + { + private int _opacity = 150; + + [Bindable(true), Category("Custom"), DefaultValue(150), Description("背景的透明度. 有效值0-255")] + public int Opacity + { + get { return _opacity; } + set + { + if (value > 255) value = 255; + else if (value < 0) value = 0; + _opacity = value; + Invalidate(); + } + } + + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT + return cp; + } + } + + protected override void AfterSetFillColor(Color color) + { + base.AfterSetFillColor(color); + BackColor = Color.FromArgb(Opacity, FillColor); + } + + protected override void OnPaintFill(Graphics g, GraphicsPath path) + { + } + } +} \ No newline at end of file diff --git a/SunnyUI/Controls/UITreeView.cs b/SunnyUI/Controls/UITreeView.cs index 28816a5f..0da3782f 100644 --- a/SunnyUI/Controls/UITreeView.cs +++ b/SunnyUI/Controls/UITreeView.cs @@ -565,9 +565,8 @@ namespace Sunny.UI { base.WndProc(ref m); - //隐藏滚动条 - ScrollBarInfo.ShowScrollBar(Handle, 3, false);//0:horizontal,1:vertical,3:both - + if (IsDisposed || Disposing) return; + ScrollBarInfo.ShowScrollBar(Handle, 3, false); if (m.Msg == 0xf || m.Msg == 0x133) { if (BorderStyle == BorderStyle.FixedSingle) diff --git a/SunnyUI/SunnyUI.csproj b/SunnyUI/SunnyUI.csproj index a31f79c1..d2070fc4 100644 --- a/SunnyUI/SunnyUI.csproj +++ b/SunnyUI/SunnyUI.csproj @@ -110,6 +110,9 @@ UserControl + + UserControl + Form diff --git a/Updates.txt b/Updates.txt index e621a1f6..d272f8f3 100644 --- a/Updates.txt +++ b/Updates.txt @@ -1,5 +1,9 @@ + ӣ - ɾ * ޸ +2020.06.08 +* UINAVMenu޸һϢBug +* UIPieChartToolTipãʾɫ + 2020.06.07 * UITabControlػҳҿưť * UIPieChartTitleLegendTip