// ***********************************************************************
// Assembly : HZH_Controls
// Created : 2019-09-11
//
// ***********************************************************************
//
// Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
//
//
// Blog: https://www.cnblogs.com/bfyx
// GitHub:https://github.com/kwwwvagaa/NetWinformControl
// gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
//
// If you use this code, please keep this note.
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace HZH_Controls.Controls
{
///
/// Class MindMappingItemEntity.
///
public class MindMappingItemEntity
{
///
/// Gets or sets the identifier.
///
/// The identifier.
public string ID { get; set; }
///
/// The text
///
private string _text;
///
/// Gets or sets the text.
///
/// The text.
public string Text
{
get { return _text; }
set
{
_text = value;
ResetSize();
}
}
///
/// Gets or sets the data source.
///
/// The data source.
public object DataSource { get; set; }
///
/// The childrens
///
private MindMappingItemEntity[] _Childrens;
///
/// Gets or sets the childrens.
///
/// The childrens.
public MindMappingItemEntity[] Childrens
{
get { return _Childrens; }
set
{
_Childrens = value;
if (value != null && value.Length > 0)
{
value.ToList().ForEach(p => { if (p != null) { p.ParentItem = this; } });
}
}
}
///
/// The back color
///
private Color? backColor;
///
/// Gets or sets the color of the back.
///
/// The color of the back.
public Color? BackColor
{
get { return backColor; }
set { backColor = value; }
}
///
/// The font
///
private Font font = new Font("微软雅黑", 10);
///
/// Gets or sets the font.
///
/// The font.
public Font Font
{
get { return font; }
set
{
font = value;
ResetSize();
}
}
///
/// The fore color
///
private Color foreColor = Color.Black;
///
/// Gets or sets the color of the fore.
///
/// The color of the fore.
public Color ForeColor
{
get { return foreColor; }
set { foreColor = value; }
}
///
/// The is expansion
///
private bool _IsExpansion = false;
///
/// Gets or sets a value indicating whether the instance is expanded.
///
/// true if this instance is expansion; otherwise, false.
public bool IsExpansion
{
get
{
return _IsExpansion;
}
set
{
if (value == _IsExpansion)
return;
_IsExpansion = value;
if (!value && _Childrens != null && _Childrens.Length > 0)
{
_Childrens.ToList().ForEach(p => { if (p != null) { p.IsExpansion = false; } });
}
}
}
///
/// Gets the parent item.
///
/// The parent item.
public MindMappingItemEntity ParentItem { get; private set; }
///
/// Gets all childrens maximum show count.
///
/// All childrens maximum show count.
public int AllChildrensMaxShowHeight { get { return GetAllChildrensMaxShowHeight(); } }
///
/// Gets the maximum level.
///
/// The maximum level.
public int AllChildrensMaxShowWidth { get { return GetAllChildrensMaxShowWidth(); } }
///
/// Gets all childrens maximum show count.
///
/// System.Int32.
private int GetAllChildrensMaxShowHeight()
{
if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
return ItemHeight + 10;
else
{
return _Childrens.Sum(p => p == null ? 0 : p.AllChildrensMaxShowHeight);
}
}
///
/// Gets the maximum level.
///
/// System.Int32.
private int GetAllChildrensMaxShowWidth()
{
if (!_IsExpansion || _Childrens == null || _Childrens.Length <= 0)
return ItemWidth + 50;
else
{
return ItemWidth + 50 + _Childrens.Max(p => p == null ? 0 : p.AllChildrensMaxShowWidth);
}
}
///
/// Gets or sets the working rectangle.
///
/// The working rectangle.
internal RectangleF WorkingRectangle { get; set; }
///
/// Gets or sets the draw rectangle.
///
/// The draw rectangle.
internal RectangleF DrawRectangle { get; set; }
///
/// Gets or sets the expansion rectangle.
///
/// The expansion rectangle.
internal RectangleF ExpansionRectangle { get; set; }
///
/// Gets the height of the item.
///
/// The height of the item.
int ItemHeight { get; set; }
///
/// Gets the width of the item.
///
/// The width of the item.
int ItemWidth { get; set; }
///
/// Resets the size.
///
private void ResetSize()
{
string _t = _text;
if (string.IsNullOrEmpty(_t))
{
_t = "aaaa";
}
Bitmap bit = new Bitmap(1, 1);
var g = Graphics.FromImage(bit);
var size = g.MeasureString(_t, font);
g.Dispose();
bit.Dispose();
ItemHeight = (int)size.Height;
ItemWidth = (int)size.Width;
}
}
}