public AutoRowHeightLayout(TreeViewAdv treeView, int rowHeight) { _rowCache = new List<Rectangle>(); _treeView = treeView; PreferredRowHeight = rowHeight; _measureContext = new DrawContext(); _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1)); }
protected override void OnPaint(PaintEventArgs e) { BeginPerformanceCount(); PerformanceAnalyzer.Start("OnPaint"); DrawContext context = new DrawContext(); context.Graphics = e.Graphics; context.Font = this.Font; context.Enabled = Enabled; int y = 0; int gridHeight = 0; if (UseColumns) { DrawColumnHeaders(e.Graphics); y += ColumnHeaderHeight; if (Columns.Count == 0 || e.ClipRectangle.Height <= y) return; } int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y; y -= firstRowY; e.Graphics.ResetTransform(); e.Graphics.TranslateTransform(-OffsetX, y); Rectangle displayRect = DisplayRectangle; for (int row = FirstVisibleRow; row < RowCount; row++) { Rectangle rowRect = _rowLayout.GetRowBounds(row); gridHeight += rowRect.Height; if (rowRect.Y + y > displayRect.Bottom) break; else DrawRow(e, ref context, row, rowRect); } if ((GridLineStyle & GridLineStyle.Vertical) == GridLineStyle.Vertical && UseColumns) DrawVerticalGridLines(e.Graphics, firstRowY); if (_dropPosition.Node != null && DragMode && HighlightDropPosition) DrawDropMark(e.Graphics); e.Graphics.ResetTransform(); DrawScrollBarsBox(e.Graphics); if (DragMode && _dragBitmap != null) e.Graphics.DrawImage(_dragBitmap, PointToClient(MousePosition)); PerformanceAnalyzer.Finish("OnPaint"); EndPerformanceCount(e); }
public void DrawNode(TreeNodeAdv node, DrawContext context) { foreach (NodeControlInfo item in GetNodeControls(node)) { if (item.Bounds.X >= OffsetX && item.Bounds.X - OffsetX < this.Bounds.Width)// skip invisible nodes { context.Bounds = item.Bounds; context.Graphics.SetClip(context.Bounds); item.Control.Draw(node, context); context.Graphics.ResetClip(); } } }
public TreeViewAdv() { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable , true); if (Application.RenderWithVisualStyles) _columnHeaderHeight = 20; else _columnHeaderHeight = 17; //BorderStyle = BorderStyle.Fixed3D; _hScrollBar.Height = SystemInformation.HorizontalScrollBarHeight; _vScrollBar.Width = SystemInformation.VerticalScrollBarWidth; _rowLayout = new FixedRowHeightLayout(this, RowHeight); _rowMap = new List<TreeNodeAdv>(); _selection = new List<TreeNodeAdv>(); _readonlySelection = new ReadOnlyCollection<TreeNodeAdv>(_selection); _columns = new TreeColumnCollection(this); _toolTip = new ToolTip(); _measureContext = new DrawContext(); _measureContext.Font = Font; _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1)); Input = new NormalInputState(this); _search = new IncrementalSearch(this); CreateNodes(); CreatePens(); ArrangeControls(); _plusMinus = new NodePlusMinus(); _controls = new NodeControlsCollection(this); Font = _font; ExpandingIcon.IconChanged += ExpandingIconChanged; }
private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect) { TreeNodeAdv node = RowMap[row]; context.DrawSelection = DrawSelectionMode.None; context.CurrentEditorOwner = _currentEditorOwner; if (DragMode) { if ((_dropPosition.Node == node) && _dropPosition.Position == NodePosition.Inside && HighlightDropPosition) context.DrawSelection = DrawSelectionMode.Active; } else { if (node.IsSelected && Focused) context.DrawSelection = DrawSelectionMode.Active; else if (node.IsSelected && !Focused && !HideSelection) context.DrawSelection = DrawSelectionMode.Inactive; } context.DrawFocus = Focused && CurrentNode == node; if (FullRowSelect) { context.DrawFocus = false; if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive) { Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, ClientRectangle.Width, rowRect.Height); if (context.DrawSelection == DrawSelectionMode.Active) { e.Graphics.FillRectangle(SystemBrushes.Highlight, focusRect); context.DrawSelection = DrawSelectionMode.FullRowSelect; } else { e.Graphics.FillRectangle(SystemBrushes.InactiveBorder, focusRect); context.DrawSelection = DrawSelectionMode.None; } } } if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal) e.Graphics.DrawLine(SystemPens.InactiveBorder, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom); if (ShowLines) DrawLines(e.Graphics, node, rowRect); DrawNode(node, context); }
private void DrawIcons() { Graphics gr = Graphics.FromHwnd(this.Handle); int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y; DrawContext context = new DrawContext(); context.Graphics = gr; for (int i = 0; i < _expandingNodes.Count; i++) { foreach (NodeControlInfo info in GetNodeControls(_expandingNodes[i])) if (info.Control is ExpandingIcon) { Rectangle rect = info.Bounds; rect.X -= OffsetX; rect.Y -= firstRowY; context.Bounds = rect; info.Control.Draw(info.Node, context); } } gr.Dispose(); }
public void DrawNode(TreeNodeAdv node, DrawContext context) { foreach (NodeControlInfo item in GetNodeControls(node)) { context.Bounds = item.Bounds; context.Graphics.SetClip(item.Bounds); item.Control.Draw(node, context); context.Graphics.ResetClip(); } }
protected override void OnPaint(PaintEventArgs e) { DrawContext context = new DrawContext(); context.Graphics = e.Graphics; context.Font = this.Font; context.Enabled = Enabled; int y = 0; if (UseColumns) { DrawColumnHeaders(e.Graphics); y = ColumnHeaderHeight; if (Columns.Count == 0) return; } e.Graphics.ResetTransform(); e.Graphics.TranslateTransform(-OffsetX, y - (FirstVisibleRow * RowHeight)); int row = FirstVisibleRow; while (row < RowCount && row - FirstVisibleRow <= PageRowCount) { TreeNodeAdv node = _rowMap[row]; context.DrawSelection = DrawSelectionMode.None; context.CurrentEditorOwner = _currentEditorOwner; if (_dragMode) { if ((_dropPosition.Node == node) && _dropPosition.Position == NodePosition.Inside) context.DrawSelection = DrawSelectionMode.Active; } else { if (node.IsSelected && Focused) context.DrawSelection = DrawSelectionMode.Active; else if (node.IsSelected && !Focused && !HideSelection) context.DrawSelection = DrawSelectionMode.Inactive; } context.DrawFocus = Focused && CurrentNode == node; if (FullRowSelect) { context.DrawFocus = false; if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive) { Rectangle focusRect = new Rectangle(OffsetX, row * RowHeight, ClientRectangle.Width, RowHeight); if (context.DrawSelection == DrawSelectionMode.Active) { e.Graphics.FillRectangle(SystemBrushes.Highlight, focusRect); context.DrawSelection = DrawSelectionMode.FullRowSelect; } else { e.Graphics.FillRectangle(SystemBrushes.InactiveBorder, focusRect); context.DrawSelection = DrawSelectionMode.None; } } } if (ShowLines) DrawLines(e.Graphics, node); DrawNode(node, context); row++; } if (_dropPosition.Node != null && _dragMode) DrawDropMark(e.Graphics); e.Graphics.ResetTransform(); DrawScrollBarsBox(e.Graphics); }