From 61860cc9951bf3a0efbab46b49d6faed8ea1a943 Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 25 Nov 2022 14:22:14 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIFlowLayoutPanel:=20=E5=A2=9E=E5=8A=A0Get?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BB=A5=E8=8E=B7=E5=8F=96=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIFlowLayoutPanel.cs | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/SunnyUI/Controls/UIFlowLayoutPanel.cs b/SunnyUI/Controls/UIFlowLayoutPanel.cs index f28fd696..910b6fcc 100644 --- a/SunnyUI/Controls/UIFlowLayoutPanel.cs +++ b/SunnyUI/Controls/UIFlowLayoutPanel.cs @@ -25,12 +25,14 @@ * 2022-11-03: V3.2.6 增加了可设置垂直滚动条宽度的属性 * 2022-11-13: V3.2.8 增加滚动条背景色调整 * 2022-11-13: V3.2.8 删除AddControl、RemoveControl方法 + * 2022-11-25: V3.2.9 增加Get方法以获取控件 ******************************************************************************/ using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; +using System.Linq; using System.Windows.Forms; namespace Sunny.UI @@ -247,6 +249,39 @@ namespace Sunny.UI Panel.Controls.Clear(); } + [Browsable(false)] + public ControlCollection AllControls => Panel.Controls; + + public T Get(string controlName) where T : Control + { + return Panel.GetControls()?.Where(p => p.Name == controlName).FirstOrDefault(); + } + + public Control Get(string controlName) + { + return Panel.Controls.ContainsKey(controlName) ? Panel.Controls[controlName] : null; + } + + public Control Get(int index) + { + return (index >= 0 && index < Panel.Controls.Count) ? Panel.Controls[index] : null; + } + + [Browsable(false)] + public int ControlCount => AllControls.Count; + + [Browsable(false)] + public Control this[string controlName] + { + get => Get(controlName); + } + + [Browsable(false)] + public Control this[int index] + { + get => Get(index); + } + private void Timer_Tick(object sender, EventArgs e) { if (VBar.Maximum != Panel.VerticalScroll.Maximum ||