+ IToolTip: 增加ToolTip接口,在用UIToolTip时解决类似UITextBox这类的组合控件无法显示ToolTip的问题

This commit is contained in:
Sunny 2021-08-16 21:51:03 +08:00
parent 122f0f402e
commit c468a8bc5e
23 changed files with 124 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,6 +29,7 @@ namespace Sunny.UI.Demo
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.uiTextBox6 = new Sunny.UI.UITextBox();
this.uiTextBox5 = new Sunny.UI.UITextBox();
this.uiTextBox4 = new Sunny.UI.UITextBox();
@ -46,6 +47,7 @@ namespace Sunny.UI.Demo
this.uiLabel1 = new Sunny.UI.UILabel();
this.uiTextBox1 = new Sunny.UI.UITextBox();
this.uiIntegerUpDown1 = new Sunny.UI.UIIntegerUpDown();
this.uiToolTip1 = new Sunny.UI.UIToolTip(this.components);
this.SuspendLayout();
//
// uiTextBox6
@ -280,6 +282,7 @@ namespace Sunny.UI.Demo
this.uiTextBox1.Size = new System.Drawing.Size(221, 29);
this.uiTextBox1.TabIndex = 0;
this.uiTextBox1.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiToolTip1.SetToolTip(this.uiTextBox1, "Hello world!");
this.uiTextBox1.Watermark = "水印文字";
//
// uiIntegerUpDown1
@ -296,6 +299,12 @@ namespace Sunny.UI.Demo
this.uiIntegerUpDown1.Text = "_uiIntegerUpDown1";
this.uiIntegerUpDown1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
//
// 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;
//
// FTextBox
//
this.AllowShowTitle = true;
@ -348,5 +357,6 @@ namespace Sunny.UI.Demo
private UILabel uiLabel1;
private UITextBox uiTextBox1;
private UIIntegerUpDown uiIntegerUpDown1;
private UIToolTip uiToolTip1;
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="uiToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -32,7 +32,7 @@ namespace Sunny.UI
[DefaultEvent("SelectedIndexChanged")]
[ToolboxItem(true)]
[LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "SelectedValue")]
public sealed partial class UIComboBox : UIDropControl
public sealed partial class UIComboBox : UIDropControl,IToolTip
{
public UIComboBox()
{
@ -49,6 +49,11 @@ namespace Sunny.UI
fullControlSelect = true;
}
public Control ExToolTipControl()
{
return edit;
}
[DefaultValue(false)]
public bool Sorted
{

View File

@ -9,7 +9,7 @@ namespace Sunny.UI
[DefaultEvent("NodeSelected")]
[DefaultProperty("Nodes")]
[ToolboxItem(true)]
public class UIComboTreeView : UIDropControl
public class UIComboTreeView : UIDropControl,IToolTip
{
public UIComboTreeView()
{
@ -32,6 +32,11 @@ namespace Sunny.UI
}
public Control ExToolTipControl()
{
return edit;
}
protected override void OnFontChanged(EventArgs e)
{
base.OnFontChanged(e);

View File

@ -22,13 +22,14 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(true)]
[DefaultProperty("Value")]
[DefaultEvent("ValueChanged")]
public sealed partial class UIDatePicker : UIDropControl
public sealed partial class UIDatePicker : UIDropControl,IToolTip
{
public delegate void OnDateTimeChanged(object sender, DateTime value);
@ -74,6 +75,11 @@ namespace Sunny.UI
}
}
public Control ExToolTipControl()
{
return edit;
}
public int Year => Value.Year;
public int Month => Value.Month;
public int Day => Value.Day;

View File

@ -24,13 +24,14 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(true)]
[DefaultProperty("Value")]
[DefaultEvent("ValueChanged")]
public sealed partial class UIDatetimePicker : UIDropControl
public sealed partial class UIDatetimePicker : UIDropControl,IToolTip
{
private void InitializeComponent()
{
@ -48,6 +49,11 @@ namespace Sunny.UI
}
public Control ExToolTipControl()
{
return edit;
}
[DefaultValue(false)]
[Description("日期输入时,是否可空显示"), Category("SunnyUI")]
public bool CanEmpty { get; set; }

View File

@ -30,7 +30,7 @@ namespace Sunny.UI
{
[DefaultEvent("ValueChanged")]
[DefaultProperty("Value")]
public sealed partial class UIDoubleUpDown : UIPanel
public sealed partial class UIDoubleUpDown : UIPanel,IToolTip
{
public delegate void OnValueChanged(object sender, double value);
@ -50,6 +50,11 @@ namespace Sunny.UI
pnlValue.Paint += PnlValue_Paint;
}
public Control ExToolTipControl()
{
return pnlValue;
}
private void PnlValue_Paint(object sender, PaintEventArgs e)
{
if (Enabled)

View File

@ -27,7 +27,7 @@ using System.Windows.Forms;
namespace Sunny.UI
{
public class UIFlowLayoutPanel : UIPanel
public class UIFlowLayoutPanel : UIPanel,IToolTip
{
private UIVerScrollBarEx VBar;
private UIHorScrollBarEx HBar;
@ -58,6 +58,11 @@ namespace Sunny.UI
timer.Start();
}
public Control ExToolTipControl()
{
return Panel;
}
public new void Focus()
{
base.Focus();

View File

@ -32,7 +32,7 @@ using System.Windows.Forms;
namespace Sunny.UI
{
[DefaultEvent("ItemClick")]
public sealed partial class UIImageListBox : UIPanel
public sealed partial class UIImageListBox : UIPanel,IToolTip
{
private readonly ImageListBox listbox = new ImageListBox();
private readonly UIScrollBar bar = new UIScrollBar();
@ -67,6 +67,11 @@ namespace Sunny.UI
listbox.MouseMove += Listbox_MouseMove;
}
public Control ExToolTipControl()
{
return listbox;
}
public int IndexFromPoint(Point p)
{
return listbox.IndexFromPoint(p);

View File

@ -30,7 +30,7 @@ namespace Sunny.UI
{
[DefaultEvent("ValueChanged")]
[DefaultProperty("Value")]
public sealed partial class UIIntegerUpDown : UIPanel
public sealed partial class UIIntegerUpDown : UIPanel,IToolTip
{
public delegate void OnValueChanged(object sender, int value);
@ -48,6 +48,11 @@ namespace Sunny.UI
pnlValue.Paint += PnlValue_Paint;
}
public Control ExToolTipControl()
{
return pnlValue;
}
private void PnlValue_Paint(object sender, PaintEventArgs e)
{
if (Enabled)

View File

@ -33,7 +33,7 @@ namespace Sunny.UI
{
[DefaultEvent("ItemClick")]
[DefaultProperty("Items")]
public sealed partial class UIListBox : UIPanel
public sealed partial class UIListBox : UIPanel,IToolTip
{
private readonly ListBoxEx listbox = new ListBoxEx();
private readonly UIScrollBar bar = new UIScrollBar();
@ -79,6 +79,11 @@ namespace Sunny.UI
timer.Start();
}
public Control ExToolTipControl()
{
return listbox;
}
private void Listbox_MouseClick(object sender, MouseEventArgs e)
{
MouseClick?.Invoke(this, e);

View File

@ -30,7 +30,7 @@ namespace Sunny.UI
{
[DefaultEvent("TextChanged")]
[DefaultProperty("Text")]
public sealed class UIRichTextBox : UIPanel
public sealed class UIRichTextBox : UIPanel,IToolTip
{
private UIScrollBar bar;
private RichTextBox edit;
@ -67,6 +67,11 @@ namespace Sunny.UI
edit.ScrollBars = RichTextBoxScrollBars.Vertical;
}
public Control ExToolTipControl()
{
return edit;
}
public RichTextBox RichTextBox => edit;
public override Color BackColor { get => edit.BackColor; set { edit.BackColor = base.BackColor = value; } }

View File

@ -33,7 +33,7 @@ namespace Sunny.UI
{
[DefaultEvent("TextChanged")]
[DefaultProperty("Text")]
public sealed partial class UITextBox : UIPanel, ISymbol
public sealed partial class UITextBox : UIPanel, ISymbol, IToolTip
{
private readonly UIEdit edit = new UIEdit();
private readonly UIScrollBar bar = new UIScrollBar();
@ -86,6 +86,11 @@ namespace Sunny.UI
TextAlignmentChange += UITextBox_TextAlignmentChange;
}
public Control ExToolTipControl()
{
return edit;
}
private void Edit_LostFocus(object sender, EventArgs e)
{
LostFocus?.Invoke(this, e);

View File

@ -23,13 +23,14 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(true)]
[DefaultProperty("Value")]
[DefaultEvent("ValueChanged")]
public sealed partial class UITimePicker : UIDropControl
public sealed partial class UITimePicker : UIDropControl,IToolTip
{
private void InitializeComponent()
{
@ -46,6 +47,11 @@ namespace Sunny.UI
this.PerformLayout();
}
public Control ExToolTipControl()
{
return edit;
}
public UITimePicker()
{
InitializeComponent();

View File

@ -93,6 +93,11 @@ namespace Sunny.UI
ToolTipControls.TryAdd(control, ctrl);
}
if (control is IToolTip toolTip)
{
SetToolTip(toolTip.ExToolTipControl(), description, title, symbol, symbolSize, symbolColor);
}
base.SetToolTip(control, description);
}
@ -117,6 +122,11 @@ namespace Sunny.UI
ToolTipControls.TryAdd(control, ctrl);
}
if (control is IToolTip toolTip)
{
SetToolTip(toolTip.ExToolTipControl(), description, title);
}
base.SetToolTip(control, description);
}
@ -139,13 +149,25 @@ namespace Sunny.UI
ToolTipControls.TryAdd(control, ctrl);
}
if (control is IToolTip toolTip)
{
SetToolTip(toolTip.ExToolTipControl(), description);
}
base.SetToolTip(control, description);
}
public void RemoveToolTip(Control control)
{
if (ToolTipControls.ContainsKey(control))
{
ToolTipControls.TryRemove(control, out _);
}
if (control is IToolTip toolTip)
{
RemoveToolTip(toolTip.ExToolTipControl());
}
}
public new string GetToolTip(Control control)

View File

@ -31,7 +31,7 @@ using System.Windows.Forms;
namespace Sunny.UI
{
public sealed class UITreeView : UIPanel
public sealed class UITreeView : UIPanel,IToolTip
{
private UIScrollBar Bar;
@ -65,6 +65,11 @@ namespace Sunny.UI
view.MouseLeave += View_MouseLeave;
}
public Control ExToolTipControl()
{
return view;
}
public new EventHandler MouseLeave;
public new EventHandler MouseEnter;
public new MouseEventHandler MouseMove;

View File

@ -1,4 +1,6 @@
namespace Sunny.UI
using System.Windows.Forms;
namespace Sunny.UI
{
public enum UIDateType
{
@ -6,4 +8,9 @@
YearMonth,
Year
}
public interface IToolTip
{
Control ExToolTipControl();
}
}