* UIFlowLayoutPanel: 增加Get方法以获取控件

This commit is contained in:
Sunny 2022-11-25 14:22:14 +08:00
parent 615a9149c5
commit 61860cc995

View File

@ -25,12 +25,14 @@
* 2022-11-03: V3.2.6 * 2022-11-03: V3.2.6
* 2022-11-13: V3.2.8 * 2022-11-13: V3.2.8
* 2022-11-13: V3.2.8 AddControlRemoveControl方法 * 2022-11-13: V3.2.8 AddControlRemoveControl方法
* 2022-11-25: V3.2.9 Get方法以获取控件
******************************************************************************/ ******************************************************************************/
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
@ -247,6 +249,39 @@ namespace Sunny.UI
Panel.Controls.Clear(); Panel.Controls.Clear();
} }
[Browsable(false)]
public ControlCollection AllControls => Panel.Controls;
public T Get<T>(string controlName) where T : Control
{
return Panel.GetControls<T>()?.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) private void Timer_Tick(object sender, EventArgs e)
{ {
if (VBar.Maximum != Panel.VerticalScroll.Maximum || if (VBar.Maximum != Panel.VerticalScroll.Maximum ||