You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
5.5 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JwKdsV.Core;
namespace JwKdsV.Component
{
public partial class ItemPanel : UserControl
{
public ItemPanel()
{
InitializeComponent();
}
private List<BaseSubItemPanel> _items = new List<BaseSubItemPanel>();
public List<BaseSubItemPanel> Items => this._items;
private int _itemSpace = 5;
public int ItemSpace
{
get
{
return _itemSpace;
}
set
{
this._itemSpace = value;
}
}
private bool _titleVisible = false;
/// <summary>
/// 标题是否显示
/// </summary>
[Category("杂项"), Description("标题是否显示")]
public bool TitleVisible
{
get
{
return _titleVisible;
}
set
{
this._titleVisible = value;
this.label1.Visible = this._titleVisible;
}
}
private string _titleText = string.Empty;
/// <summary>
/// 标题
/// </summary>
[Category("杂项"), Description("标题文本")]
public string TitleText
{
get
{
return _titleText;
}
set
{
this._titleText = value;
this.label1.Text = this._titleText;
}
}
private Font _titleFont = Global.Instance.GetFont( SystemFont.);
[Category("杂项"), Description("标题文本字体")]
public Font TitleFont
{
get
{
return _titleFont;
}
set
{
this._titleFont = value;
this.label1.Font = this._titleFont;
}
}
private Color _titleFontColor = Color.White;
[Category("杂项"), Description("标题文本颜色")]
public Color TitleFontColor
{
get
{
return _titleFontColor;
}
set
{
this._titleFontColor = value;
this.label1.ForeColor = this._titleFontColor;
}
}
private Color _titleBackColor = Color.Black;
[Category("杂项"), Description("标题背景颜色")]
public Color TitleBackColor
{
get
{
return _titleBackColor;
}
set
{
this._titleBackColor = value;
this.label1.BackColor = this._titleBackColor;
}
}
/// <summary>
/// 清空所有控件
/// </summary>
public void Clear()
{
_items = null;
_items = new List<BaseSubItemPanel>();
this.panel1.Controls.Clear();
this.Invalidate();
}
public void RefreshView()
{
//this.panel1.Controls.Clear();
var ch = this.panel1.Height;
var cw = this.panel1.Width;
int tempX = 0, tempY = 0;
//移除删除的item
List<BaseSubItemPanel> removeList = new List<BaseSubItemPanel>();
foreach(var control in this.panel1.Controls)
{
if(control is BaseSubItemPanel)
{
var item = control as BaseSubItemPanel;
if(!Items.Exists(x => x.Name == item.Name))
{
removeList.Add(item);
}
}
}
foreach(var removeItem in removeList)
{
///zhangy Add-----------2020-10-23----------
while (removeItem.Controls.Count > 0)
{
if (removeItem.Controls[0] != null)
{
var ctl = removeItem.Controls[0];
if (ctl is Panel)
{
while (ctl.Controls.Count > 0)
{
if (ctl.Controls[0] != null)
{
var subctl = ctl.Controls[0];
subctl.Dispose();
}
}
ctl.Controls.Clear();
}
ctl.Dispose();
}
}
removeItem.Controls.Clear();
removeItem.Dispose();
///zhangy Add-----------2020-10-23----------
///
this.panel1.Controls.Remove(removeItem);
}
//重定位
foreach(var item in Items)
{
if(tempX + item.Width + this.ItemSpace > cw)
{
tempX = 0;
tempY += item.Height + this.ItemSpace;
}
item.Location = new Point(tempX, tempY);
tempX += item.Width + this.ItemSpace;
if(this.panel1.Controls.Find(item.Name, false).Count() == 0)
{
this.panel1.Controls.Add(item);
}
}
this.Invalidate();
}
}
}