* UIFlowLayoutPanel: 可像原生控件一样通过Controls.Add增加。

This commit is contained in:
Sunny 2021-07-31 10:17:25 +08:00
parent 7a6371a1f5
commit 2454ad20aa
18 changed files with 172 additions and 171 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

@ -31,6 +31,8 @@ namespace Sunny.UI.Demo
{
this.uiButton1 = new Sunny.UI.UIButton();
this.uiFlowLayoutPanel1 = new Sunny.UI.UIFlowLayoutPanel();
this.uiButton2 = new Sunny.UI.UIButton();
this.uiButton3 = new Sunny.UI.UIButton();
this.SuspendLayout();
//
// uiButton1
@ -42,7 +44,7 @@ namespace Sunny.UI.Demo
this.uiButton1.Name = "uiButton1";
this.uiButton1.Size = new System.Drawing.Size(100, 35);
this.uiButton1.TabIndex = 11;
this.uiButton1.Text = "AddControl";
this.uiButton1.Text = "增加";
this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
//
// uiFlowLayoutPanel1
@ -53,16 +55,43 @@ namespace Sunny.UI.Demo
this.uiFlowLayoutPanel1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiFlowLayoutPanel1.Name = "uiFlowLayoutPanel1";
this.uiFlowLayoutPanel1.Padding = new System.Windows.Forms.Padding(2);
this.uiFlowLayoutPanel1.Size = new System.Drawing.Size(249, 390);
this.uiFlowLayoutPanel1.Size = new System.Drawing.Size(334, 390);
this.uiFlowLayoutPanel1.TabIndex = 10;
this.uiFlowLayoutPanel1.Text = "uiFlowLayoutPanel1";
this.uiFlowLayoutPanel1.Text = "`";
this.uiFlowLayoutPanel1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiButton2
//
this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiButton2.Location = new System.Drawing.Point(264, 462);
this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton2.Name = "uiButton2";
this.uiButton2.Size = new System.Drawing.Size(100, 35);
this.uiButton2.TabIndex = 12;
this.uiButton2.Text = "清除";
this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
//
// uiButton3
//
this.uiButton3.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton3.Enabled = false;
this.uiButton3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiButton3.Location = new System.Drawing.Point(147, 462);
this.uiButton3.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton3.Name = "uiButton3";
this.uiButton3.Size = new System.Drawing.Size(100, 35);
this.uiButton3.TabIndex = 13;
this.uiButton3.Text = "移除";
this.uiButton3.Click += new System.EventHandler(this.uiButton3_Click);
//
// FFlowLayoutPanel
//
this.AllowShowTitle = true;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(800, 539);
this.Controls.Add(this.uiButton3);
this.Controls.Add(this.uiButton2);
this.Controls.Add(this.uiButton1);
this.Controls.Add(this.uiFlowLayoutPanel1);
this.Name = "FFlowLayoutPanel";
@ -78,5 +107,7 @@ namespace Sunny.UI.Demo
private UIButton uiButton1;
private UIFlowLayoutPanel uiFlowLayoutPanel1;
private UIButton uiButton2;
private UIButton uiButton3;
}
}

View File

@ -13,18 +13,49 @@
uiFlowLayoutPanel1.Clear();
index = 0;
for (int i = 0; i < 30; i++)
for (int i = 0; i < 20; i++)
{
uiButton1.PerformClick();
}
}
private int index;
UIButton btn;
private void uiButton1_Click(object sender, System.EventArgs e)
{
UIButton btn = new UIButton();
btn = new UIButton();
btn.Text = "Button" + index++.ToString("D2");
uiFlowLayoutPanel1.AddControl(btn);
//可以用原生方法Controls.Add
uiFlowLayoutPanel1.Controls.Add(btn);
//或者封装的方法Add
//uiFlowLayoutPanel1.Add(btn);
uiButton3.Enabled = true;
}
private void uiButton2_Click(object sender, System.EventArgs e)
{
//清除用Clear方法
uiFlowLayoutPanel1.Clear();
//或者用
//uiFlowLayoutPanel1.Panel.Controls.Clear();
uiButton3.Enabled = false;
}
private void uiButton3_Click(object sender, System.EventArgs e)
{
if (btn != null)
{
//移除用Remove方法
uiFlowLayoutPanel1.Remove(btn);
//或者用
//uiFlowLayoutPanel1.Panel.Controls.Remove(btn);
btn = null;
}
uiButton3.Enabled = false;
}
}
}

View File

@ -1,59 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"SunnyUI.Net5.Demo/3.0.5": {
"dependencies": {
"SunnyUI": "3.0.5"
},
"runtime": {
"SunnyUI.Net5.Demo.dll": {}
}
},
"SunnyUI/3.0.5": {
"dependencies": {
"SunnyUI.Common": "3.0.5"
},
"runtime": {
"lib/net5.0-windows7.0/SunnyUI.dll": {
"assemblyVersion": "3.0.5.0",
"fileVersion": "3.0.5.0"
}
}
},
"SunnyUI.Common/3.0.5": {
"runtime": {
"lib/net5.0/SunnyUI.Common.dll": {
"assemblyVersion": "3.0.5.0",
"fileVersion": "3.0.5.0"
}
}
}
}
},
"libraries": {
"SunnyUI.Net5.Demo/3.0.5": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"SunnyUI/3.0.5": {
"type": "package",
"serviceable": true,
"sha512": "sha512-0+U39GWGWBQFmoZom+UOzuST9FxsbUol5RWZgnBLzfGDlR+O4C72HjQ38u9G/SppWBswr5+dmGvFYHBA2HS4uQ==",
"path": "sunnyui/3.0.5",
"hashPath": "sunnyui.3.0.5.nupkg.sha512"
},
"SunnyUI.Common/3.0.5": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bP9fQW8P4fJAV6FfU2Xfw3MtOduLoj/j+MRfdIn3eq9bGqDepg/w5/xqXi393Vuxvxk24eY9+5YMRVyeS+tiRg==",
"path": "sunnyui.common/3.0.5",
"hashPath": "sunnyui.common.3.0.5.nupkg.sha512"
}
}
}

View File

@ -1,8 +0,0 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Administrator\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Administrator\\.nuget\\packages"
]
}
}

View File

@ -1,9 +0,0 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.WindowsDesktop.App",
"version": "5.0.0"
}
}
}

View File

@ -58,11 +58,108 @@ namespace Sunny.UI
timer.Start();
}
~UIFlowLayoutPanel()
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
timer.Stop();
}
protected override void OnControlAdded(ControlEventArgs e)
{
if (e.Control is UIHorScrollBarEx bar1)
{
if (bar1.TagString == "79E1E7DD-3E4D-916B-C8F1-F45B579C290C")
{
base.OnControlAdded(e);
return;
}
}
if (e.Control is UIVerScrollBarEx bar2)
{
if (bar2.TagString == "63FD1249-41D3-E08A-F8F5-CC41CC30FD03")
{
base.OnControlAdded(e);
return;
}
}
if (e.Control is FlowLayoutPanel panel)
{
if (panel.Tag.ToString() == "69605093-6397-AD32-9F69-3C29F642F87E")
{
base.OnControlAdded(e);
return;
}
}
if (Panel != null && !IsDesignMode)
{
Add(e.Control);
}
else
{
base.OnControlAdded(e);
if (Panel != null) Panel.SendToBack();
}
}
public void Remove(Control control)
{
if (Panel != null)
{
if (Panel.Controls.Contains(control))
Panel.Controls.Remove(control);
}
}
public void Add(Control control)
{
if (control is IStyleInterface ctrl)
{
if (!ctrl.StyleCustomMode) ctrl.Style = Style;
}
if (Panel != null)
{
Panel.Controls.Add(control);
}
}
[Obsolete("此方法已优化用Add代替")]
public void AddControl(Control control)
{
if (control is IStyleInterface ctrl)
{
if (!ctrl.StyleCustomMode) ctrl.Style = Style;
}
if (Panel != null)
{
Panel.Controls.Add(control);
}
}
[Obsolete("此方法已优化用Remove代替")]
public void RemoveControl(Control control)
{
if (Panel != null)
{
if (Panel.Controls.Contains(control))
Panel.Controls.Remove(control);
}
}
public void Clear()
{
foreach (Control control in Panel.Controls)
{
control.Dispose();
}
Panel.Controls.Clear();
}
private void Timer_Tick(object sender, EventArgs e)
{
if (VBar.Maximum != Panel.VerticalScroll.Maximum ||
@ -145,31 +242,6 @@ namespace Sunny.UI
}
}
public void AddControl(Control control)
{
if (control is IStyleInterface ctrl)
{
if (!ctrl.StyleCustomMode) ctrl.Style = Style;
}
Panel.Controls.Add(control);
}
public void RemoveControl(Control control)
{
Panel.Controls.Remove(control);
}
public void Clear()
{
foreach (Control control in Panel.Controls)
{
control.Dispose();
}
Panel.Controls.Clear();
}
private void Panel_MouseClick(object sender, MouseEventArgs e)
{
Panel.Focus();
@ -277,11 +349,12 @@ namespace Sunny.UI
this.flowLayoutPanel.Name = "flowLayoutPanel";
this.flowLayoutPanel.Size = new System.Drawing.Size(429, 383);
this.flowLayoutPanel.TabIndex = 0;
this.flowLayoutPanel.Tag = "69605093-6397-AD32-9F69-3C29F642F87E";
//
// VBar
//
this.VBar.BoundsHeight = 10;
this.VBar.Font = new System.Drawing.Font("微软雅黑", 12F);
this.VBar.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.VBar.LargeChange = 10;
this.VBar.Location = new System.Drawing.Point(410, 5);
this.VBar.Maximum = 100;
@ -289,6 +362,7 @@ namespace Sunny.UI
this.VBar.Name = "VBar";
this.VBar.Size = new System.Drawing.Size(18, 377);
this.VBar.TabIndex = 1;
this.VBar.TagString = "63FD1249-41D3-E08A-F8F5-CC41CC30FD03";
this.VBar.Text = "uiVerScrollBarEx1";
this.VBar.Value = 0;
this.VBar.Visible = false;
@ -296,7 +370,7 @@ namespace Sunny.UI
// HBar
//
this.HBar.BoundsWidth = 10;
this.HBar.Font = new System.Drawing.Font("微软雅黑", 12F);
this.HBar.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.HBar.LargeChange = 10;
this.HBar.Location = new System.Drawing.Point(5, 364);
this.HBar.Maximum = 100;
@ -304,6 +378,7 @@ namespace Sunny.UI
this.HBar.Name = "HBar";
this.HBar.Size = new System.Drawing.Size(399, 18);
this.HBar.TabIndex = 2;
this.HBar.TagString = "79E1E7DD-3E4D-916B-C8F1-F45B579C290C";
this.HBar.Text = "uiHorScrollBarEx1";
this.HBar.Value = 0;
this.HBar.Visible = false;

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">