using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
namespace Dongke.WinForm.Controls
{
///
/// 显示标记项的分层集合,每个标记项用一个 TreeNode 来表示。
///
[ToolboxBitmap(typeof(TreeView))]
public partial class TvwTreeView : TreeView, IDKControl, IAsyncControl
{
#region 成员变量
///
/// 展开节点的图像的图像列表索引值。
///
private int _expandImageIndex = -1;
private int _expandSelectedImageIndex = -1;
#endregion
#region 构造函数
///
/// 显示标记项的分层集合,每个标记项用一个 TreeNode 来表示。
///
public TvwTreeView()
{
}
#endregion
#region 属性
/////
///// 获取或设置树展开节点显示的默认图像的图像列表索引值。
/////
//[DefaultValue(-1)]
//[Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
//[Localizable(true)]
//[RefreshProperties(RefreshProperties.Repaint)]
//[TypeConverter(typeof(NoneExcludedImageIndexConverter))]
//[RelatedImageList("ImageList")]
//public int ExpandImageIndex
//{
// get
// {
// return this._expandImageIndex;
// }
// set
// {
// if (this._expandImageIndex != value)
// {
// this._expandImageIndex = value;
// this.SetImageIndex();
// }
// }
//}
#endregion
#region 重写事件
///
/// 在选中树节点复选框后发生。
///
///
protected override void OnAfterCheck(TreeViewEventArgs e)
{
base.OnAfterCheck(e);
//if (e.Node.Nodes.Count > 0)
//{
// e.Node
//}
}
#endregion
#region 私有方法
///
/// 设置节点的图像的图像列表索引值
///
private void SetImageIndex()
{
this.BeginUpdate();
this.SetImageIndex(null);
this.EndUpdate();
}
private void SetImageIndex(TreeNode node)
{
if (node != null)
{
if (node.IsExpanded)
{
node.ImageIndex = this._expandImageIndex;
node.SelectedImageIndex = this._expandSelectedImageIndex;
}
else
{
node.ImageIndex = -1;
node.SelectedImageIndex = -1;
}
foreach (TreeNode item in node.Nodes)
{
this.SetImageIndex(item);
}
}
else
{
foreach (TreeNode item in this.Nodes)
{
this.SetImageIndex(item);
}
}
}
#endregion
#region
#endregion
#region IAsyncControl 成员
#region 成员变量
///
/// 异步处理开始时,控件状态
///
private bool _asyncBeginStatus = false;
private bool _asyncBeginFocused = false;
#endregion
#region 公有方法
///
/// 开始异步处理
///
/// 是否处理焦点
public virtual void BeginAsync(ref bool doFocus)
{
if (doFocus && this.Focused)
{
this._asyncBeginFocused = true;
doFocus = false;
}
this._asyncBeginStatus = this.Enabled;
this.Enabled = false;
}
///
/// 结束异步处理
///
public virtual void EndAsync()
{
this.Enabled = this._asyncBeginStatus;
if (this._asyncBeginFocused)
{
this.Focus();
}
}
#endregion
#endregion
}
}