| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
-
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Windows.Forms;
- namespace Dongke.WinForm.Controls
- {
- /// <summary>
- /// 显示标记项的分层集合,每个标记项用一个 TreeNode 来表示。
- /// </summary>
- [ToolboxBitmap(typeof(TreeView))]
- public partial class TvwTreeView : TreeView, IDKControl, IAsyncControl
- {
- #region 成员变量
- /// <summary>
- /// 展开节点的图像的图像列表索引值。
- /// </summary>
- private int _expandImageIndex = -1;
- private int _expandSelectedImageIndex = -1;
- #endregion
- #region 构造函数
- /// <summary>
- /// 显示标记项的分层集合,每个标记项用一个 TreeNode 来表示。
- /// </summary>
- public TvwTreeView()
- {
- }
- #endregion
- #region 属性
- ///// <summary>
- ///// 获取或设置树展开节点显示的默认图像的图像列表索引值。
- ///// </summary>
- //[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 重写事件
- /// <summary>
- /// 在选中树节点复选框后发生。
- /// </summary>
- /// <param name="e"></param>
- protected override void OnAfterCheck(TreeViewEventArgs e)
- {
- base.OnAfterCheck(e);
- //if (e.Node.Nodes.Count > 0)
- //{
- // e.Node
- //}
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 设置节点的图像的图像列表索引值
- /// </summary>
- 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 成员变量
- /// <summary>
- /// 异步处理开始时,控件状态
- /// </summary>
- private bool _asyncBeginStatus = false;
- private bool _asyncBeginFocused = false;
- #endregion
- #region 公有方法
- /// <summary>
- /// 开始异步处理
- /// </summary>
- /// <param name="doFocus">是否处理焦点</param>
- public virtual void BeginAsync(ref bool doFocus)
- {
- if (doFocus && this.Focused)
- {
- this._asyncBeginFocused = true;
- doFocus = false;
- }
- this._asyncBeginStatus = this.Enabled;
- this.Enabled = false;
- }
- /// <summary>
- /// 结束异步处理
- /// </summary>
- public virtual void EndAsync()
- {
- this.Enabled = this._asyncBeginStatus;
- if (this._asyncBeginFocused)
- {
- this.Focus();
- }
- }
- #endregion
- #endregion
- }
- }
|