diff --git a/Bin/SunnyUI.dll b/Bin/SunnyUI.dll index 48cf7b60..64e4e482 100644 Binary files a/Bin/SunnyUI.dll and b/Bin/SunnyUI.dll differ diff --git a/Bin/SunnyUI.pdb b/Bin/SunnyUI.pdb index b57e2445..71cad208 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 0cabd543..96c7e2ee 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 48cf7b60..64e4e482 100644 Binary files a/SunnyUI.Demo/Bin/SunnyUI.dll and b/SunnyUI.Demo/Bin/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FButton.Designer.cs b/SunnyUI.Demo/Controls/FButton.Designer.cs index 5adfc1a9..deef2b09 100644 --- a/SunnyUI.Demo/Controls/FButton.Designer.cs +++ b/SunnyUI.Demo/Controls/FButton.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.uiButton1 = new Sunny.UI.UIButton(); this.uiButton2 = new Sunny.UI.UIButton(); this.uiButton3 = new Sunny.UI.UIButton(); @@ -81,6 +82,7 @@ this.uiImageButton2 = new Sunny.UI.UIImageButton(); this.uiImageButton3 = new Sunny.UI.UIImageButton(); this.uiImageButton4 = new Sunny.UI.UIImageButton(); + this.uiToolTip1 = new Sunny.UI.UIToolTip(this.components); this.PagePanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.uiImageButton1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.uiImageButton2)).BeginInit(); @@ -144,7 +146,6 @@ this.PagePanel.Controls.Add(this.uiButton2); this.PagePanel.Controls.Add(this.uiButton1); this.PagePanel.Size = new System.Drawing.Size(800, 499); - this.PagePanel.Style = Sunny.UI.UIStyle.Blue; this.PagePanel.Text = ""; // // uiButton1 @@ -167,6 +168,7 @@ this.uiButton1.StyleCustomMode = true; this.uiButton1.TabIndex = 0; this.uiButton1.Text = "White"; + this.uiButton1.TipsText = "White"; // // uiButton2 // @@ -179,6 +181,7 @@ this.uiButton2.StyleCustomMode = true; this.uiButton2.TabIndex = 1; this.uiButton2.Text = "Blue"; + this.uiButton2.TipsText = "Blue"; // // uiButton3 // @@ -983,6 +986,13 @@ this.uiImageButton4.Text = "Home"; this.uiImageButton4.TextAlign = System.Drawing.ContentAlignment.BottomCenter; // + // uiToolTip1 + // + this.uiToolTip1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54))))); + this.uiToolTip1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(239)))), ((int)(((byte)(239)))), ((int)(((byte)(239))))); + this.uiToolTip1.OwnerDraw = true; + this.uiToolTip1.ToolTipTitle = "ToolTip title"; + // // FButton // this.AlwaysOpen = true; @@ -1056,5 +1066,6 @@ private UIImageButton uiImageButton2; private UIImageButton uiImageButton1; private UIImageButton uiImageButton4; + private UIToolTip uiToolTip1; } } \ No newline at end of file diff --git a/SunnyUI.Demo/Controls/FButton.cs b/SunnyUI.Demo/Controls/FButton.cs index e75440d6..0cf158c6 100644 --- a/SunnyUI.Demo/Controls/FButton.cs +++ b/SunnyUI.Demo/Controls/FButton.cs @@ -8,6 +8,10 @@ namespace Sunny.UI.Demo public FButton() { InitializeComponent(); + uiToolTip1.SetToolTip(uiButton1,uiButton1.Text); + uiToolTip1.SetToolTip(uiSymbolButton1,uiSymbolButton1.Text,"SunnyUI"); + uiToolTip1.SetToolTip(uiSymbolButton2, uiSymbolButton2.Text, "SunnyUI", + uiSymbolButton2.Symbol, 32,UIColor.Red); } } } \ No newline at end of file diff --git a/SunnyUI.Demo/Controls/FButton.resx b/SunnyUI.Demo/Controls/FButton.resx index 1af7de15..8018e1c6 100644 --- a/SunnyUI.Demo/Controls/FButton.resx +++ b/SunnyUI.Demo/Controls/FButton.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/SunnyUI/Controls/UIToolTip.cs b/SunnyUI/Controls/UIToolTip.cs new file mode 100644 index 00000000..52658b08 --- /dev/null +++ b/SunnyUI/Controls/UIToolTip.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Concurrent; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace Sunny.UI +{ + public class UIToolTip : ToolTip + { + private readonly ConcurrentDictionary ToolTipControls = + new ConcurrentDictionary(); + + public UIToolTip() + { + InitOwnerDraw(); + } + + public UIToolTip(IContainer cont) + : base(cont) + { + InitOwnerDraw(); + } + + public new string ToolTipTitle { get; set; } = "ToolTip title"; + + [DefaultValue(typeof(Font), "微软雅黑, 9pt")] + public Font Font { get; set; } = new Font("微软雅黑", 9); + + [DefaultValue(typeof(Font), "微软雅黑, 12pt")] + public Font TitleFont { get; set; } = new Font("微软雅黑", 12); + + [DefaultValue(typeof(Color), "239, 239, 239")] + public Color RectColor { get; set; } = UIChartStyles.Dark.ForeColor; + + [DefaultValue(true)] public bool AutoSize { get; set; } = true; + + [DefaultValue(typeof(Size), "100, 70")] + public Size Size { get; set; } = new Size(100, 70); + + public void SetToolTip(Control control, string description, string title, int symbol, int symbolSize, + Color symbolColor) + { + if (title == null) title = string.Empty; + + if (ToolTipControls.ContainsKey(control)) + { + ToolTipControls[control].Title = title; + ToolTipControls[control].Description = description; + ToolTipControls[control].Symbol = symbol; + ToolTipControls[control].SymbolSize = symbolSize; + ToolTipControls[control].SymbolColor = symbolColor; + } + else + { + var ctrl = new ToolTipControl() + { + Control = control, + Title = title, + Description = description, + Symbol = symbol, + SymbolSize = symbolSize, + SymbolColor = symbolColor + }; + + ToolTipControls.TryAdd(control, ctrl); + } + + base.SetToolTip(control, description); + } + + public void SetToolTip(Control control, string description, string title) + { + if (title == null) title = string.Empty; + + if (ToolTipControls.ContainsKey(control)) + { + ToolTipControls[control].Title = title; + ToolTipControls[control].Description = description; + } + else + { + var ctrl = new ToolTipControl() + { + Control = control, + Title = title, + Description = description + }; + + ToolTipControls.TryAdd(control, ctrl); + } + + base.SetToolTip(control, description); + } + + public new void SetToolTip(Control control, string description) + { + if (ToolTipControls.ContainsKey(control)) + { + ToolTipControls[control].Title = string.Empty; + ToolTipControls[control].Description = description; + } + else + { + var ctrl = new ToolTipControl + { + Control = control, + Title = string.Empty, + Description = description + }; + + ToolTipControls.TryAdd(control, ctrl); + } + + base.SetToolTip(control, description); + } + + public void RemoveToolTip(Control control) + { + if (ToolTipControls.ContainsKey(control)) + ToolTipControls.TryRemove(control, out _); + } + + public new ToolTipControl GetToolTip(Control control) + { + return ToolTipControls.ContainsKey(control) ? ToolTipControls[control] : new ToolTipControl(); + } + + private void InitOwnerDraw() + { + OwnerDraw = true; + Draw += ToolTipExDraw; + Popup += UIToolTip_Popup; + + BackColor = UIChartStyles.Dark.BackColor; + ForeColor = UIChartStyles.Dark.ForeColor; + RectColor = UIChartStyles.Dark.ForeColor; + } + + private void UIToolTip_Popup(object sender, PopupEventArgs e) + { + if (ToolTipControls.ContainsKey(e.AssociatedControl)) + { + var tooltip = ToolTipControls[e.AssociatedControl]; + + if (tooltip.Description.IsValid()) + { + if (!AutoSize) + { + e.ToolTipSize = Size; + } + else + { + var bmp = new Bitmap(e.ToolTipSize.Width, e.ToolTipSize.Height); + var g = Graphics.FromImage(bmp); + + int symbolWidth = tooltip.Symbol > 0 ? tooltip.SymbolSize : 0; + int symbolHeight = tooltip.Symbol > 0 ? tooltip.SymbolSize : 0; + + SizeF titleSize = new SizeF(0, 0); + if (tooltip.Title.IsValid()) + { + titleSize = g.MeasureString(tooltip.Title, TitleFont); + } + + SizeF textSize = g.MeasureString(tooltip.Description, Font); + + TitleHeight = (int)Math.Max(symbolHeight, titleSize.Height); + + e.ToolTipSize = new Size((int)Math.Max(textSize.Width, symbolWidth + titleSize.Width) + 10, (int)textSize.Height + TitleHeight + 10); + bmp.Dispose(); + } + } + } + } + + private int TitleHeight; + + private void ToolTipExDraw(object sender, DrawToolTipEventArgs e) + { + if (ToolTipControls.ContainsKey(e.AssociatedControl)) + { + var tooltip = ToolTipControls[e.AssociatedControl]; + + var bounds = new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1); + + e.Graphics.FillRectangle(BackColor, bounds); + e.Graphics.DrawRectangle(RectColor, bounds); + + if (tooltip.Symbol > 0) + e.Graphics.DrawFontImage(tooltip.Symbol, tooltip.SymbolSize, tooltip.SymbolColor, new Rectangle(5, 5, tooltip.SymbolSize, tooltip.SymbolSize)); + if (tooltip.Title.IsValid()) + { + SizeF sf = e.Graphics.MeasureString(tooltip.Title, TitleFont); + e.Graphics.DrawString(tooltip.Title,TitleFont,ForeColor, tooltip.Symbol>0?tooltip.SymbolSize+5:5, (TitleHeight-sf.Height)/2); + } + + e.Graphics.DrawString(e.ToolTipText, Font, ForeColor, 6, TitleHeight + 6); + } + else + { + e.Graphics.DrawString(e.ToolTipText, e.Font, ForeColor, 0, 0); + } + } + + public class ToolTipControl + { + public Control Control { get; set; } + public string Title { get; set; } + public string Description { get; set; } + + public int Symbol { get; set; } = 0; + + public int SymbolSize { get; set; } = 32; + + public Color SymbolColor { get; set; } = UIChartStyles.Dark.ForeColor; + } + } +} \ No newline at end of file diff --git a/SunnyUI/SunnyUI.csproj b/SunnyUI/SunnyUI.csproj index 8ceeae56..8cab9645 100644 --- a/SunnyUI/SunnyUI.csproj +++ b/SunnyUI/SunnyUI.csproj @@ -396,6 +396,9 @@ UserControl + + Component + Component