SunnyUI/SunnyUI.Demo/Controls/FFlowLayoutPanel.cs

116 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.Windows.Forms;
namespace Sunny.UI.Demo
{
public partial class FFlowLayoutPanel : UIPage
{
public FFlowLayoutPanel()
{
InitializeComponent();
}
public override void Init()
{
base.Init();
2020-09-29 17:27:24 +08:00
uiFlowLayoutPanel1.Clear();
index = 0;
for (int i = 0; i < 10; i++)
{
2023-10-11 22:50:09 +08:00
uiButton1_Click(null, null);
}
}
private int index;
2023-10-11 22:50:09 +08:00
UIFlowItem btn;
private void uiButton1_Click(object sender, System.EventArgs e)
{
2023-10-11 22:50:09 +08:00
btn = new UIFlowItem();
btn.SetDPIScale();
btn.Text = "Button" + index++.ToString("D2");
2022-11-29 14:22:19 +08:00
btn.Name = btn.Text;
btn.Click += Btn_Click;
2021-08-01 10:57:52 +08:00
//建议用封装的方法Add
uiFlowLayoutPanel1.Add(btn);
2023-03-05 11:53:45 +08:00
2022-11-29 14:22:19 +08:00
//或者Panel.Controls.Add
//uiFlowLayoutPanel1.Panel.Controls.Add(btn);
//不能用原生方法Controls.Add
2023-10-11 22:50:09 +08:00
//----uiFlowLayoutPanel1.Controls.Add(btn);----
2023-03-05 11:53:45 +08:00
uiButton3.Enabled = true;
2023-11-18 11:38:29 +08:00
this.Render();
}
private void Btn_Click(object sender, System.EventArgs e)
{
2023-10-11 22:50:09 +08:00
var button = (UIFlowItem)sender;
2024-05-02 23:04:38 +08:00
this.ShowInfoTip(button.Text);
}
private void uiButton2_Click(object sender, System.EventArgs e)
{
//清除用Clear方法
uiFlowLayoutPanel1.Clear();
//或者用
//uiFlowLayoutPanel1.Panel.Controls.Clear();
2022-11-29 14:22:19 +08:00
//不能用原生方法Controls.Clear
2023-10-11 22:50:09 +08:00
//----uiFlowLayoutPanel1.Controls.Clear();----
2022-11-29 14:22:19 +08:00
uiButton3.Enabled = false;
}
private void uiButton3_Click(object sender, System.EventArgs e)
{
if (btn != null)
{
//移除用Remove方法
uiFlowLayoutPanel1.Remove(btn);
//或者用
//uiFlowLayoutPanel1.Panel.Controls.Remove(btn);
2022-11-29 14:22:19 +08:00
//不能用原生方法Controls.Remove
2023-10-11 22:50:09 +08:00
//----uiFlowLayoutPanel1.Controls.Remove(btn);----
2022-11-29 14:22:19 +08:00
btn = null;
}
uiButton3.Enabled = false;
}
2022-11-29 14:22:19 +08:00
private void uiButton4_Click(object sender, System.EventArgs e)
{
//根据名称获取
var btn = uiFlowLayoutPanel1.Get("Button01");
//通过控件名称索引获取
btn = uiFlowLayoutPanel1["Button01"];
//通过名称和类型获取
2023-10-11 22:50:09 +08:00
var button = uiFlowLayoutPanel1.Get<UIFlowItem>("Button01");
//遍历,方法一
for (int i = 0; i < uiFlowLayoutPanel1.ControlCount; i++)
{
Console.WriteLine(uiFlowLayoutPanel1.Get(i).Name);
}
//遍历,方法二
foreach (Control item in uiFlowLayoutPanel1.AllControls)
{
Console.WriteLine(item.Name);
}
2023-10-11 22:50:09 +08:00
//遍历方法三与原生方法不同UIFlowLayoutPanel是组合控件从其Panel控件遍历
foreach (Control item in uiFlowLayoutPanel1.Panel.Controls)
{
Console.WriteLine(item.Name);
}
2022-11-29 14:22:19 +08:00
}
}
}