📄 painttreectrl.cs
字号:
rc.Width = rc.Width;
base.Invalidate(rc);
num = 0;
}
}
}
private bool IsNeedPaint(PaintTreeNode paintNode)
{
bool flag = false;
for (int i = 0; i < paintNode.Columns.Count; i++)
{
if (paintNode.Columns[i].ColumnType == PaintTreeColumnType.IMAGE)
{
flag = true;
break;
}
}
if (!flag)
{
if (!paintNode.IsExpanded)
{
return false;
}
foreach (TreeNode node in paintNode.Nodes)
{
PaintTreeNode node2 = node as PaintTreeNode;
if (this.IsNeedPaint(node2))
{
break;
}
}
}
return true;
}
private bool IsVisible(TreeNode node)
{
return true;
}
public int MeasureItems()
{
if (this.Nodes.Count == 0)
{
return 0;
}
int location = 0;
for (int i = 0; i < this.Nodes.Count; i++)
{
this.MeasureSingleRootItem(this.Nodes[i], ref location);
}
PaintTreeNode node = this.Nodes[this.Nodes.Count - 1] as PaintTreeNode;
Rectangle paintTreeNodeBounds = node.PaintTreeNodeBounds;
int num3 = location;
if (this.Nodes.Count == 0)
{
return (location + paintTreeNodeBounds.Height);
}
if (!this.Nodes[this.Nodes.Count - 1].LastNode.IsExpanded)
{
return num3;
}
while (node.LastNode != null)
{
node = node.LastNode as PaintTreeNode;
}
return (paintTreeNodeBounds.Height + location);
}
private void MeasureSingleRootItem(TreeNode pnd, ref int location)
{
PaintTreeNode node = pnd as PaintTreeNode;
Rectangle paintTreeNodeBounds = node.PaintTreeNodeBounds;
location = paintTreeNodeBounds.Top + paintTreeNodeBounds.Height;
if (pnd.IsExpanded)
{
for (int i = 0; i < pnd.Nodes.Count; i++)
{
TreeNode node1 = pnd.Nodes[i];
location += paintTreeNodeBounds.Height;
this.MeasureSingleRootItem(pnd.Nodes[i], ref location);
}
}
}
private PaintTreeNodeCollection node_OnGotNodes(PaintTreeNode node)
{
return node._nodes;
}
private int node_OnNodeAdded(TreeNode node)
{
return base.SelectedNode.Nodes.Add(node);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
new Region();
this._clipedRectangle = e.ClipRectangle;
if (this.Nodes.Count != 0)
{
this._OffsetY = base.ClientRectangle.Y - this.Nodes[0].Bounds.Y;
if (this._clipedRectangle.Size != base.ClientRectangle.Size)
{
int num = 0x10;
for (int i = 0; i < this._clipedRectangle.Height; i += num)
{
TreeNode nodeAt = base.GetNodeAt(0, (i + this._clipedRectangle.Y) + (num / 2));
if (nodeAt == null)
{
nodeAt = base.GetNodeAt(0, (i + this._clipedRectangle.Y) + (num / 2));
}
if (nodeAt == null)
{
return;
}
this.PaintNode(g, nodeAt);
}
}
else
{
int num3 = 0x10;
for (int j = 0; j < this._clipedRectangle.Height; j += num3)
{
TreeNode node = base.GetNodeAt(0, j + this._clipedRectangle.Y);
if (node == null)
{
node = base.GetNodeAt(0, (j + this._clipedRectangle.Y) + (num3 / 2));
}
if (node == null)
{
return;
}
this.PaintNode(g, node);
}
}
}
}
private void PaintBackGround(Graphics g)
{
}
private void PaintColumn(Graphics g, PaintTreeColumn column, Rectangle rect)
{
if (column.ColumnType == PaintTreeColumnType.TEXT)
{
StringFormat format = new StringFormat();
format.FormatFlags = StringFormatFlags.NoWrap;
TreeDrawHelper.DrawString(g, column.ColumnFont, column.ColumnColor, rect, column.ColumnText, format);
}
else if (column.ColumnType == PaintTreeColumnType.IMAGE)
{
TreeDrawHelper.DrawImage(g, rect, column.image.NextFrame(100), false);
}
}
private void PaintNode(Graphics g, TreeNode node)
{
if (node != null)
{
bool selected;
if (node == this.SelectedNode)
{
selected = true;
}
else
{
if ((node.Bounds.Left == 0) && (node.Bounds.Top == 0))
{
return;
}
selected = false;
}
this.PaintNodeColumns(g, node, selected);
if (node.Nodes.Count > 0)
{
this.DrawPlusMinusImg(g, node);
}
}
}
private void PaintNodeColoumn(Graphics g, TreeNode node, int column, bool selected)
{
PaintTreeNode node2 = node as PaintTreeNode;
string columnText = node2.Columns[column].ColumnText;
Rectangle filler = this.CalculateColumnRect(g, node, column);
if (selected)
{
TreeDrawHelper.FillRectangle(g, filler, this._selectionColor);
}
this.PaintColumn(g, node2.Columns[column], filler);
}
private void PaintNodeColumns(Graphics g, TreeNode node, bool selected)
{
PaintTreeNode node2 = node as PaintTreeNode;
for (int i = 0; i < node2.Columns.ColumnCount; i++)
{
this.PaintNodeColoumn(g, node, i, selected);
}
if (selected)
{
Rectangle rectangle = new Rectangle(0, 0, 0, 0);
int num2 = 0;
for (int j = 0; j < node2.Columns.ColumnCount; j++)
{
Rectangle rectangle2 = this.CalculateColumnRect(g, node, j);
if (!this.CanPaint(node, j))
{
return;
}
if (num2 == 0)
{
rectangle.X = rectangle2.Left;
rectangle.Y = rectangle2.Top;
rectangle.Height = rectangle2.Height;
}
num2 += rectangle2.Width;
rectangle.Width = num2;
if (node2.Columns[j].bHoverRectangle)
{
Rectangle border = this.CaculateBorder(node2.Columns[j].ColumnRec);
TreeDrawHelper.DrawRectangle(g, border, this._selectBorderColor);
num2 = 0;
}
}
}
}
private bool PtInRect(Point pt, Rectangle rect)
{
return (((pt.X > rect.Left) && (pt.X < rect.Right)) && ((pt.Y > rect.Top) && (pt.Y < rect.Bottom)));
}
private bool RectIntercept(Rectangle rect1, Rectangle rect2)
{
Rectangle rectangle = Rectangle.Intersect(rect1, rect2);
if ((rectangle.Width == 0) && (rectangle.Height == 0))
{
return false;
}
return true;
}
public Color BackColor
{
get
{
return this._bkColor;
}
set
{
this._bkColor = value;
}
}
protected override bool DoubleBuffered
{
get
{
return true;
}
set
{
this.set_DoubleBuffered(value);
}
}
public PaintTreeNodeCollection Nodes
{
get
{
return this._nodes;
}
}
public Color SelectBorderColor
{
get
{
return this._selectBorderColor;
}
set
{
this._selectBorderColor = value;
}
}
public PaintTreeNode SelectedNode
{
get
{
return (base.SelectedNode as PaintTreeNode);
}
set
{
base.Invalidate();
base.SelectedNode = value;
}
}
public Color SelectionColor
{
get
{
return this._selectionColor;
}
set
{
this._selectionColor = value;
}
}
public bool Sorted
{
get
{
return true;
}
set
{
this._sorted = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -