📄 painttreectrl.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class PaintTreeCtrl : TreeView
{
private Color _bkColor = Color.FromArgb(0xff, 0xff, 0xff);
private Rectangle _clipedRectangle;
private PaintTreeNodeCollection _nodes;
private int _OffsetY;
private Color _selectBorderColor = Color.FromArgb(0x83, 150, 0xc3);
private Color _selectionColor = Color.BlueViolet;
private bool _sorted;
protected IContainer components;
private ImageList imageList1;
public PaintTreeCtrl()
{
this.InitializeComponent();
base.SetStyle(ControlStyles.UserPaint, true);
this._nodes = new PaintTreeNodeCollection();
this._nodes.OnNodeAdded += new NodeAdded(this._nodes_OnNodeAdded);
this._nodes.OnNodeGot += new NodeGot(this._nodes_OnNodeGot);
this._nodes.OnNodeRemove += new NodeRemoveAt(this._nodes_OnNodeRemove);
this._nodes.OnNodeClear += new NodeClear(this._nodes_OnNodeClear);
this._nodes.OnNodeCount += new NodeCount(this._nodes_OnNodeCount);
base.set_ShowNodeToolTips(false);
}
private int _nodes_OnNodeAdded(TreeNode node)
{
return base.Nodes.Add(node);
}
private void _nodes_OnNodeClear()
{
base.Nodes.Clear();
}
private int _nodes_OnNodeCount()
{
return base.Nodes.Count;
}
private TreeNode _nodes_OnNodeGot(int index)
{
return base.Nodes[index];
}
private void _nodes_OnNodeRemove(int index)
{
base.Nodes.RemoveAt(index);
}
private Rectangle CaculateBorder(Rectangle area)
{
return new Rectangle(area.Left, area.Top - 1, area.Width, area.Height);
}
private Rectangle CalculateColumnRect(Graphics g, TreeNode node, int column)
{
PaintTreeNode node2 = node as PaintTreeNode;
Rectangle columnRec = node2.Columns[column].ColumnRec;
if (column == 0)
{
columnRec.X = node.Bounds.Left;
columnRec.Y = node.Bounds.Top + 1;
}
else
{
columnRec.X = node2.Columns[column - 1].ColumnRec.Right + node2.Columns[column].ident;
columnRec.Y = node2.Columns[column - 1].ColumnRec.Top;
}
if (node2.Columns[column].ColumnType == PaintTreeColumnType.TEXT)
{
SizeF ef = g.MeasureString(node2.Columns[column].ColumnText, node2.Columns[column].ColumnFont);
columnRec.Width = (int) Math.Ceiling((double) ef.Width);
columnRec.Height = (int) Math.Ceiling((double) ef.Height);
}
else if (node2.Columns[column].ColumnType == PaintTreeColumnType.IMAGE)
{
columnRec.Height = base.ItemHeight - 2;
if (node2.Columns[column].image.IsValidImage())
{
columnRec.Width = (columnRec.Height * node2.Columns[column].image.Width) / node2.Columns[column].image.Height;
}
}
node2.Columns[column].ColumnRec = columnRec;
return columnRec;
}
private bool CanPaint(TreeNode node)
{
PaintTreeNode node2 = node as PaintTreeNode;
Rectangle a = node2.Bounds;
if ((a.Width != 0) || (a.Height != 0))
{
if ((node.Parent != null) && !node.Parent.IsExpanded)
{
return false;
}
Rectangle rectangle2 = Rectangle.Intersect(a, this._clipedRectangle);
if ((rectangle2.Width == 0) && (rectangle2.Height == 0))
{
return false;
}
}
return true;
}
private bool CanPaint(TreeNode node, int column)
{
PaintTreeNode node2 = node as PaintTreeNode;
Rectangle a = node2.Columns[column].ColumnRec;
if ((a.Width == 0) && (a.Height == 0))
{
DateTime now = DateTime.Now;
return true;
}
if (node.Parent != null)
{
DateTime time2 = DateTime.Now;
if (!node.Parent.IsExpanded)
{
return false;
}
}
Rectangle rectangle2 = Rectangle.Intersect(a, this._clipedRectangle);
if ((rectangle2.Width == 0) && (rectangle2.Height == 0))
{
DateTime time3 = DateTime.Now;
}
return true;
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void DrawPlusMinusImg(Graphics g, TreeNode node)
{
Rectangle rect = node.Bounds;
rect.X = (rect.Left - 10) - 5;
rect.Y = rect.Top;
rect.Width = 11;
rect.Height = 11;
if (node.IsExpanded)
{
TreeDrawHelper.DrawImage(g, rect, this.imageList1.Images[1], false);
}
else
{
TreeDrawHelper.DrawImage(g, rect, this.imageList1.Images[0], false);
}
}
private TreeNode GetDownNode(TreeNode curNode)
{
if ((curNode == this.Nodes[this.Nodes.Count - 1]) && !curNode.IsExpanded)
{
return null;
}
if (curNode.IsExpanded)
{
return curNode.FirstNode;
}
if (curNode.NextNode != null)
{
return curNode.NextNode;
}
TreeNode parent = curNode;
while (parent.Parent != null)
{
parent = parent.Parent;
if (parent.Parent != null)
{
if (parent.NextNode != null)
{
return parent.NextNode;
}
}
else
{
if (parent != this.Nodes[this.Nodes.Count - 1])
{
return parent.NextNode;
}
return null;
}
}
return parent.NextNode;
}
private void InitializeComponent()
{
this.components = new Container();
ComponentResourceManager manager = new ComponentResourceManager(typeof(PaintTreeCtrl));
this.imageList1 = new ImageList(this.components);
base.SuspendLayout();
this.imageList1.ImageStream = (ImageListStreamer) manager.GetObject("imageList1.ImageStream");
this.imageList1.TransparentColor = Color.Transparent;
this.imageList1.Images.SetKeyName(0, "collapsed.bmp");
this.imageList1.Images.SetKeyName(1, "expanded.bmp");
base.FullRowSelect = true;
base.HideSelection = false;
base.set_LineColor(Color.Black);
base.set_ShowNodeToolTips(true);
base.ResumeLayout(false);
}
protected virtual void InvalidateImage(TreeNode node)
{
PaintTreeNode node2 = node as PaintTreeNode;
if (((node2 != null) && ((node.Parent == null) || node.Parent.IsExpanded)) && this.RectIntercept(node2.Bounds, base.ClientRectangle))
{
for (int i = 0; i < node2.Columns.Count; i++)
{
if (node2.Columns[i].ColumnType == PaintTreeColumnType.IMAGE)
{
Rectangle rc;
using (Graphics g = base.CreateGraphics())
{
rc = this.CalculateColumnRect(g, node, i);
}
if (!this.RectIntercept(node2.Columns[i].ColumnRec, base.ClientRectangle))
{
return;
}
base.Invalidate(rc);
}
}
}
}
private void InvalidateImage(TreeNode node, int offset)
{
PaintTreeNode node2 = node as PaintTreeNode;
if (((node2 != null) && ((node.Parent == null) || node.Parent.IsExpanded)) && this.RectIntercept(node2.Bounds, base.ClientRectangle))
{
for (int i = 0; i < node2.Columns.Count; i++)
{
if (node2.Columns[i].ColumnType == PaintTreeColumnType.IMAGE)
{
Rectangle rc = node2.Columns[i].ColumnRec;
rc.Y += offset;
base.Invalidate(rc);
}
if (!this.RectIntercept(node2.Columns[i].ColumnRec, base.ClientRectangle))
{
return;
}
}
if ((node.Nodes.Count > 0) && node.IsExpanded)
{
for (int j = 0; j < node.Nodes.Count; j++)
{
TreeNode node3 = node.Nodes[j];
if (!node.IsExpanded)
{
return;
}
if (!this.RectIntercept(node3.Bounds, base.ClientRectangle))
{
return;
}
this.InvalidateImage(node3, offset);
}
}
}
}
private void InvalideNode(TreeNode node)
{
PaintTreeNode node2 = node as PaintTreeNode;
int count = node2.Columns.Count;
this._OffsetY = base.ClientRectangle.Y - this.Nodes[0].Bounds.Y;
Rectangle area = new Rectangle(0, 0, 0, 0);
int num = 0;
for (int i = 0; i < node2.Columns.ColumnCount; i++)
{
Rectangle columnRec = node2.Columns[i].ColumnRec;
if (i == (node2.Columns.Count - 1))
{
columnRec.Width++;
}
if (num == 0)
{
area.X = columnRec.Left;
area.Y = node.Bounds.Y;
area.Height = columnRec.Height + 2;
}
num += columnRec.Width;
area.Width = num;
if (node2.Columns[i].bHoverRectangle)
{
Rectangle rc = this.CaculateBorder(area);
rc.Width += 2;
base.Invalidate(rc);
num = 0;
}
}
}
private void InvalideNode(TreeNode node, Point point)
{
PaintTreeNode node2 = node as PaintTreeNode;
int count = node2.Columns.Count;
Rectangle area = new Rectangle(0, 0, 0, 0);
int num = 0;
for (int i = 0; i < node2.Columns.ColumnCount; i++)
{
Rectangle columnRec = node2.Columns[i].ColumnRec;
if (num == 0)
{
area.X = columnRec.Left;
area.Y = columnRec.Top;
area.Height = columnRec.Height;
}
num += columnRec.Width;
area.Width = num;
if (node2.Columns[i].bHoverRectangle && this.PtInRect(point, node2.Columns[i].ColumnRec))
{
Rectangle rc = this.CaculateBorder(area);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -