diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 6b6aa513..95bb8435 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Common/UGDI.cs b/SunnyUI/Common/UGDI.cs index 1eb25c55..de5d0684 100644 --- a/SunnyUI/Common/UGDI.cs +++ b/SunnyUI/Common/UGDI.cs @@ -57,6 +57,26 @@ namespace Sunny.UI } } + public static Size Size(this SizeF size) + { + return new Size(size.Width.RoundEx(), size.Height.RoundEx()); + } + + public static Point Point(this PointF point) + { + return new Point(point.X.RoundEx(), point.Y.RoundEx()); + } + + public static Size Add(this Size size, int width, int height) + { + return new Size(size.Width + width, size.Height + height); + } + + public static SizeF Add(this SizeF size, float width, float height) + { + return new SizeF(size.Width + width, size.Height + height); + } + /// /// 点是否在区域内 /// @@ -126,7 +146,7 @@ namespace Sunny.UI /// 提供一个Graphics,常用于需要计算文字大小时 /// /// 大小 - public static Graphics Graphics() + private static Graphics Graphics() { if (TempGraphics == null) { diff --git a/SunnyUI/Controls/DropItem/UIColorItem.cs b/SunnyUI/Controls/DropItem/UIColorItem.cs index 73124eff..f2a8f278 100644 --- a/SunnyUI/Controls/DropItem/UIColorItem.cs +++ b/SunnyUI/Controls/DropItem/UIColorItem.cs @@ -578,13 +578,13 @@ namespace Sunny.UI private void btnCancel_Click(object sender, EventArgs e) { - CloseParent(); + Close(); } private void btnOK_Click(object sender, EventArgs e) { DoValueChanged(this, SelectedColor); - CloseParent(); + Close(); } private void m_colorSample_Paint(object sender, System.Windows.Forms.PaintEventArgs e) diff --git a/SunnyUI/Controls/DropItem/UIComboBoxItem.cs b/SunnyUI/Controls/DropItem/UIComboBoxItem.cs index bc271c0c..5319748f 100644 --- a/SunnyUI/Controls/DropItem/UIComboBoxItem.cs +++ b/SunnyUI/Controls/DropItem/UIComboBoxItem.cs @@ -44,7 +44,7 @@ namespace Sunny.UI private void ListBox_Click(object sender, EventArgs e) { - CloseParent(); + Close(); } /// @@ -74,7 +74,7 @@ namespace Sunny.UI { if (e.KeyCode == System.Windows.Forms.Keys.Enter || e.KeyCode == System.Windows.Forms.Keys.Space) { - CloseParent(); + Close(); } } } diff --git a/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs b/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs index 16a06abd..04bf717f 100644 --- a/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs +++ b/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs @@ -262,12 +262,12 @@ namespace Sunny.UI DoValueChanged(this, dataGridView.SelectedIndex); } - CloseParent(); + Close(); } private void btnCancel_Click(object sender, System.EventArgs e) { - CloseParent(); + Close(); } public bool ShowFilter @@ -317,5 +317,18 @@ namespace Sunny.UI btnSearch.PerformClick(); DoValueChanged(this, null); } + + public override void InitShow() + { + if (ShowFilter) + { + edtFilter.Focus(); + edtFilter.SelectAll(); + } + else + { + btnOK.Focus(); + } + } } } diff --git a/SunnyUI/Controls/DropItem/UIComboTreeViewItem.cs b/SunnyUI/Controls/DropItem/UIComboTreeViewItem.cs index ecae8b7d..fb65c7fb 100644 --- a/SunnyUI/Controls/DropItem/UIComboTreeViewItem.cs +++ b/SunnyUI/Controls/DropItem/UIComboTreeViewItem.cs @@ -145,7 +145,7 @@ namespace Sunny.UI if (e.Node.Nodes.Count == 0 || CanSelectRootNode) { DoValueChanged(this, e.Node); - CloseParent(); + Close(); } } } @@ -159,13 +159,13 @@ namespace Sunny.UI private void btnCancel_Click(object sender, System.EventArgs e) { - CloseParent(); + Close(); } private void btnOK_Click(object sender, System.EventArgs e) { DoValueChanged(this, treeView.Nodes); - CloseParent(); + Close(); } } } diff --git a/SunnyUI/Controls/DropItem/UIDateItem.cs b/SunnyUI/Controls/DropItem/UIDateItem.cs index fcf2deb6..0658cb80 100644 --- a/SunnyUI/Controls/DropItem/UIDateItem.cs +++ b/SunnyUI/Controls/DropItem/UIDateItem.cs @@ -592,7 +592,7 @@ namespace Sunny.UI { date = new DateTime(Year, Month, 1); DoValueChanged(this, Date); - CloseParent(); + Close(); } else { @@ -667,7 +667,7 @@ namespace Sunny.UI { date = new DateTime(Year, 1, 1); DoValueChanged(this, Date); - CloseParent(); + Close(); } else { @@ -771,7 +771,7 @@ namespace Sunny.UI } DoValueChanged(this, Date); - CloseParent(); + Close(); } public Color PrimaryColor { get; set; } = UIColor.Blue; diff --git a/SunnyUI/Controls/DropItem/UIDateTimeItem.cs b/SunnyUI/Controls/DropItem/UIDateTimeItem.cs index 59a15ced..de264934 100644 --- a/SunnyUI/Controls/DropItem/UIDateTimeItem.cs +++ b/SunnyUI/Controls/DropItem/UIDateTimeItem.cs @@ -1089,14 +1089,14 @@ namespace Sunny.UI private void btnCancel_Click(object sender, EventArgs e) { - CloseParent(); + Close(); } private void btnOK_Click(object sender, EventArgs e) { DateTime time = new DateTime(Date.Year, Date.Month, Date.Day, Hour, Minute, Second); DoValueChanged(this, time); - CloseParent(); + Close(); } private void hc_DoubleClick(object sender, EventArgs e) diff --git a/SunnyUI/Controls/DropItem/UIDropDown.cs b/SunnyUI/Controls/DropItem/UIDropDown.cs index 8a30f644..384be4af 100644 --- a/SunnyUI/Controls/DropItem/UIDropDown.cs +++ b/SunnyUI/Controls/DropItem/UIDropDown.cs @@ -301,6 +301,7 @@ namespace Sunny.UI protected override void OnOpened(EventArgs e) { Item.Focus(); + Item.InitShow(); base.OnOpened(e); } diff --git a/SunnyUI/Controls/DropItem/UIDropDownItem.cs b/SunnyUI/Controls/DropItem/UIDropDownItem.cs index ba611eb8..512cc1f9 100644 --- a/SunnyUI/Controls/DropItem/UIDropDownItem.cs +++ b/SunnyUI/Controls/DropItem/UIDropDownItem.cs @@ -88,19 +88,19 @@ namespace Sunny.UI /// /// 关闭弹出窗口 /// - protected void CloseParent() + public void Close() { UIDropDown parent = (UIDropDown)Parent; parent?.Close(); } - public void Close() - { - CloseParent(); - } - public virtual void SetStyle(UIBaseStyle style) { } + + public virtual void InitShow() + { + + } } } \ No newline at end of file diff --git a/SunnyUI/Controls/DropItem/UITimeItem.cs b/SunnyUI/Controls/DropItem/UITimeItem.cs index 64107e1c..167f6876 100644 --- a/SunnyUI/Controls/DropItem/UITimeItem.cs +++ b/SunnyUI/Controls/DropItem/UITimeItem.cs @@ -587,12 +587,12 @@ namespace Sunny.UI { time = new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, Hour, Minute, Second); DoValueChanged(this, time); - CloseParent(); + Close(); } private void btnCancel_Click(object sender, EventArgs e) { - CloseParent(); + Close(); } public override void SetStyle(UIBaseStyle style) diff --git a/SunnyUI/Controls/UIToolTip.cs b/SunnyUI/Controls/UIToolTip.cs index 3ac0b555..91485c82 100644 --- a/SunnyUI/Controls/UIToolTip.cs +++ b/SunnyUI/Controls/UIToolTip.cs @@ -174,32 +174,27 @@ namespace Sunny.UI } else { - var bmp = new Bitmap(e.ToolTipSize.Width, e.ToolTipSize.Height); - var g = Graphics.FromImage(bmp); int symbolWidth = tooltip.Symbol > 0 ? tooltip.SymbolSize : 0; - - SizeF titleSize = new SizeF(0, 0); if (tooltip.Title.IsValid()) { - titleSize = g.MeasureString(tooltip.Title, TempTitleFont); + titleSize = GDI.MeasureString(tooltip.Title, TempTitleFont); } - SizeF textSize = g.MeasureString(tooltip.ToolTipText, TempTitleFont); + SizeF textSize = GDI.MeasureString(tooltip.ToolTipText, TempFont); int allWidth = (int)Math.Max(textSize.Width, titleSize.Width) + 10; if (symbolWidth > 0) allWidth = allWidth + symbolWidth + 5; int allHeight = titleSize.Height > 0 ? (int)titleSize.Height + (int)textSize.Height + 15 : (int)textSize.Height + 10; e.ToolTipSize = new Size(allWidth, allHeight); - bmp.Dispose(); } } } else { - SizeF sf = GDI.MeasureString(GetToolTip(e.AssociatedControl), TempTitleFont); - e.ToolTipSize = new Size((int)sf.Width + 10, (int)sf.Height + 10); + SizeF sf = GDI.MeasureString(GetToolTip(e.AssociatedControl), TempFont); + e.ToolTipSize = sf.Size().Add(10, 10); } } @@ -269,13 +264,13 @@ namespace Sunny.UI e.Bounds.Width - 5, 5 + titleSize.Height + 3); } - e.Graphics.DrawString(e.ToolTipText, TempTitleFont, ForeColor, + e.Graphics.DrawString(e.ToolTipText, TempFont, ForeColor, tooltip.Symbol > 0 ? tooltip.SymbolSize + 5 : 5, titleSize.Height > 0 ? 10 + titleSize.Height : 5); } else { - e.Graphics.DrawString(e.ToolTipText, TempTitleFont, ForeColor, 5, 5); + e.Graphics.DrawString(e.ToolTipText, TempFont, ForeColor, 5, 5); } }