public AutoHeaderHeightLayout(TreeViewAdv treeView, int headerHeight)
		{
			_treeView = treeView;
			PreferredHeaderHeight = headerHeight;
			_measureContext = new DrawContext();
			_measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1));
		}
示例#2
0
        public void AutoSizeColumn(TreeColumn column)
        {
            if (!Columns.Contains(column))
                throw new ArgumentException("column");

            DrawContext context = new DrawContext();
            context.Graphics = Graphics.FromImage(new Bitmap(1, 1));
            context.Font = this.Font;
            int res = 0;
            for (int row = 0; row < RowCount; row++)
            {
                if (row < RowMap.Count)
                {
                    int w = 0;
                    TreeNodeAdv node = RowMap[row];
                    foreach (NodeControl nc in NodeControls)
                    {
                        if (nc.ParentColumn == column)
                            w += nc.GetActualSize(node, _measureContext).Width;
                    }
                    res = Math.Max(res, w);
                }
            }

            if (res > 0)
                column.Width = res;
        }
        public override void Draw(TreeNodeAdv node, DrawContext context)
        {
            Graphics g = context.Graphics;
            Rectangle targetRect = new Rectangle(
                context.Bounds.X + this.LeftMargin,
                context.Bounds.Y,
                context.Bounds.Width - this.LeftMargin,
                context.Bounds.Height);

            // Retrieve item information
            PackageItem item = node.Tag as PackageItem;
            Image typeIcon = null;
            if (item != null)
            {
                switch (item.Type)
                {
                    case PackageItem.PackageType.Core:
                        typeIcon = PackageManagerFrontendResCache.IconCore;
                        break;
                    case PackageItem.PackageType.Editor:
                        typeIcon = PackageManagerFrontendResCache.IconEditor;
                        break;
                    case PackageItem.PackageType.Sample:
                        typeIcon = PackageManagerFrontendResCache.IconSample;
                        break;
                }
            }
            if (typeIcon == null) return;

            // Draw icon centered
            Point iconPos = new Point(
                targetRect.X + targetRect.Width / 2 - typeIcon.Width / 2,
                targetRect.Y + targetRect.Height / 2 - typeIcon.Height / 2);
            g.DrawImageUnscaled(typeIcon, iconPos.X, iconPos.Y);
        }
示例#4
0
        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
                {
                    if (!DragMode)
                    {
                        if (ColumnSelectionMode == ColumnSelectionMode.All)
                        {
                            if (node.IsSelected && Focused)
                                context.DrawSelection = DrawSelectionMode.Active;
                            else if (node.IsSelected && !Focused && !HideSelection)
                                context.DrawSelection = DrawSelectionMode.Inactive;
                        }
                        else
                        {
                            bool selectedColumn = ((item.Control != null) && (item.Control.ParentColumn != null) && (this.SelectedColumnIndex == item.Control.ParentColumn.Index));
                            if (node.IsSelected && Focused && selectedColumn)
                                context.DrawSelection = DrawSelectionMode.Active;
                            else if (node.IsSelected && !Focused && !HideSelection && selectedColumn)
                                context.DrawSelection = DrawSelectionMode.Inactive;
                            else
                                context.DrawSelection = DrawSelectionMode.None;
                        }
                    }

                    context.Bounds = item.Bounds;
                    context.Graphics.SetClip(context.Bounds);
                    item.Control.Draw(node, context);
                    context.Graphics.ResetClip();
                }
            }
        }
		public TreeViewRowDrawEventArgs(Graphics graphics, Rectangle clipRectangle, TreeNodeAdv node, DrawContext context, int row, Rectangle rowRect)
			: base(graphics, clipRectangle)
		{
			_node = node;
			_context = context;
			_row = row;
			_rowRect = rowRect;
		}
		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));
		}
 public void DrawNode(TreeNodeAdv node, DrawContext context)
 {
     foreach (NodeControlInfo item in GetNodeControls(node))
     {
         context.Bounds = item.Bounds;
         context.Graphics.SetClip(context.Bounds);
         item.Control.Draw(node, context);
         context.Graphics.ResetClip();
     }
 }
		public override void Draw(TreeNodeAdv node, DrawContext context)
		{
			Graphics g = context.Graphics;
			Rectangle targetRect = new Rectangle(
				context.Bounds.X + this.LeftMargin,
				context.Bounds.Y,
				context.Bounds.Width - this.LeftMargin,
				context.Bounds.Height);

			// Retrieve item information
			PackageItem item = node.Tag as PackageItem;
			if (item == null) return;

			string headline = null;
			string summary = null;
			if (item != null)
			{
				headline = item.Title;
				if (item.ItemPackageInfo != null)
				{
					summary = item.ItemPackageInfo.Summary;
				}
			}

			// Calculate drawing layout and data
			StringFormat headlineFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap };
			StringFormat summaryFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.LineLimit };
			Rectangle headlineRect;
			Rectangle summaryRect;
			{
				SizeF headlineSize;
				SizeF summarySize;
				// Base info
				{
					headlineSize = g.MeasureString(headline, context.Font, targetRect.Width, headlineFormat);
					headlineRect = new Rectangle(targetRect.X, targetRect.Y, targetRect.Width, (int)headlineSize.Height + 2);
					summaryRect = new Rectangle(targetRect.X, targetRect.Y + headlineRect.Height, targetRect.Width, targetRect.Height - headlineRect.Height);
					summarySize = g.MeasureString(summary, context.Font, summaryRect.Size, summaryFormat);
				}
				// Alignment info
				{
					Size totelContentSize = new Size(Math.Max(headlineRect.Width, summaryRect.Width), headlineRect.Height + (int)summarySize.Height);
					Point alignAdjust = new Point(0, Math.Max((targetRect.Height - totelContentSize.Height) / 2, 0));
					headlineRect.X += alignAdjust.X;
					headlineRect.Y += alignAdjust.Y;
					summaryRect.X += alignAdjust.X;
					summaryRect.Y += alignAdjust.Y;
				}
			}

			Color textColor = this.Parent.ForeColor;

			g.DrawString(headline, context.Font, new SolidBrush(Color.FromArgb(context.Enabled ? 255 : 128, textColor)), headlineRect, headlineFormat);
			g.DrawString(summary, context.Font, new SolidBrush(Color.FromArgb(context.Enabled ? 128 : 64, textColor)), summaryRect, summaryFormat);
		}
	    private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect)
		{
		    TreeNodeAdv node = this.RowMap[row];

		    context.DrawSelection = DrawSelectionMode.None;
		    context.CurrentEditorOwner = _currentEditorOwner;

		    bool focused = this.Focused;

		    if (node.IsSelected && focused)
		    {
		        context.DrawSelection = DrawSelectionMode.Active;
		    }
		    else if (node.IsSelected && !focused && !this.HideSelection)
		    {
		        context.DrawSelection = DrawSelectionMode.Inactive;
		    }

            Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, this.Width - (this._vScrollBar.Visible ? this._vScrollBar.Width : 0), rowRect.Height);

		    context.DrawFocus = false;

		    if (context.DrawSelection != DrawSelectionMode.Active)
		    {
                using (SolidBrush b = new SolidBrush(node.BackColor))
                {
                    e.Graphics.FillRectangle(b, focusRect);
                }
		    }

		    if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
		    {
		        if (context.DrawSelection == DrawSelectionMode.Active)
		        {
		            context.DrawSelection = DrawSelectionMode.FullRowSelect;

                    if (ExplorerVisualStyle.VisualStylesEnabled)
                    {
                        ExplorerVisualStyle.TvItemSelectedRenderer.DrawBackground(context.Graphics, focusRect);
                    }
                    else
                    {
		                e.Graphics.FillRectangle(SystemBrushes.Highlight, focusRect);
		            }
		        }
		        else
		        {
		            context.DrawSelection = DrawSelectionMode.None;
		        }
		    }

		    this.DrawNode(node, context);
		}
示例#10
0
        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);
        }
示例#11
0
 public void DrawNode(TreeNodeAdv node, DrawContext context)
 {
     foreach (NodeControlInfo item in GetNodeControls(node))
     {
         if (item.Bounds.Right >= 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();
         }
     }
 }
示例#12
0
        public TreeViewAdv()
        {
            InitializeComponent();
               SetStyle(ControlStyles.AllPaintingInWmPaint
            | ControlStyles.UserPaint
            | ControlStyles.OptimizedDoubleBuffer
            | ControlStyles.ResizeRedraw
            | ControlStyles.Selectable
            , true);

            if (Environment.OSVersion.Version.Major < 6)
            {
                if (Application.RenderWithVisualStyles)
                    _columnHeaderHeight = 20;
                else
                    _columnHeaderHeight = 17;
            }
            else
            {
                if (Application.RenderWithVisualStyles)
                    _columnHeaderHeight = 25;
                else
                    _columnHeaderHeight = 17;
            }

               _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(this);
               _controls = new NodeControlsCollection(this);

            Font = _font;
               ExpandingIcon.IconChanged += ExpandingIconChanged;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
#if DEBUG
            this.BeginPerformanceCount();
#endif
            DrawContext context = new DrawContext
            {
                Graphics = e.Graphics, 
                Font = this.Font, 
                Enabled = Enabled
            };

            this.DrawColumnHeaders(e.Graphics);

            int y = this.ColumnHeaderHeight;

            if (this.Columns.Count == 0 || e.ClipRectangle.Height <= y)
                return;

            int firstRowY = _rowLayout.GetRowBounds(this.FirstVisibleRow).Y;

            y -= firstRowY;

            e.Graphics.ResetTransform();
            e.Graphics.TranslateTransform(-OffsetX, y);

            Rectangle displayRect = e.ClipRectangle;

            for (int row = this.FirstVisibleRow; row < this.RowCount; row++)
            {
                Rectangle rowRect = _rowLayout.GetRowBounds(row);

                if (rowRect.Y + y > displayRect.Bottom)
                    break;

                this.DrawRow(e, ref context, row, rowRect);
            }

            e.Graphics.ResetTransform();

            this.DrawScrollBarsBox(e.Graphics);

#if DEBUG
            this.EndPerformanceCount(e);
#endif
        }
示例#14
0
        public override void Draw(TreeNodeAdv node, DrawContext context)
        {
            PlotterInfo info = GetValue(node) as PlotterInfo;

            if (_plotter == null)
            {
                _plotter = new Plotter
                {
                    BackColor = Color.Black, 
                    ShowGrid = false, 
                    OverlaySecondLine = false
                };
            }

            if (info.UseLongData)
            {
                _plotter.UseLongData = true;
                _plotter.LongData1 = info.LongData1;
                _plotter.LongData2 = info.LongData2;
            }
            else
            {
                _plotter.UseLongData = false;
                _plotter.Data1 = info.Data1;
                _plotter.Data2 = info.Data2;
            }

            _plotter.UseSecondLine = info.UseSecondLine;
            _plotter.OverlaySecondLine = info.OverlaySecondLine;
            _plotter.LineColor1 = info.LineColor1;
            _plotter.LineColor2 = info.LineColor2;

            if ((_plotter.Width != context.Bounds.Width - 1 || 
                _plotter.Height != context.Bounds.Height - 1) &&
                context.Bounds.Width > 1 && context.Bounds.Height > 1)
                _plotter.Size = new Size(context.Bounds.Width - 1, context.Bounds.Height - 1);

            _plotter.Draw();

            using (Bitmap b = new Bitmap(_plotter.Width, _plotter.Height))
            {
                _plotter.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));

                context.Graphics.DrawImage(b, context.Bounds.Location);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BeginPerformanceCount();

            DrawContext context = new DrawContext();
            context.Graphics = e.Graphics;
            context.Font = this.Font;
            context.Enabled = Enabled;

            int y = 0;
            if (HeaderStyle != ColumnHeaderStyle.None)
            {
                DrawColumnHeaders(e.Graphics);
                y += ColumnHeaderHeight;
                if (Columns.Count == 0 /*|| e.ClipRectangle.Height <= y*/)
                    return;
            }
            y -= _rowLayout.GetRowBounds(FirstVisibleRow).Y;

            e.Graphics.ResetTransform();
            e.Graphics.TranslateTransform(-OffsetX, y);
            Rectangle displayRect = DisplayRectangle;
            for (int row = FirstVisibleRow; row < RowCount; row++)
            {
                Rectangle rowRect = _rowLayout.GetRowBounds(row);
                if (rowRect.Y + y > displayRect.Bottom)
                    break;
                else
                    DrawRow(e, ref context, row, rowRect);
            }

            if (Search.IsActive)
                Search.Draw(context);

            if (_dropPosition.Node != null && DragMode)
                DrawDropMark(e.Graphics);

            e.Graphics.ResetTransform();
            DrawScrollBarsBox(e.Graphics);

            if (DragMode && _dragBitmap != null)
                e.Graphics.DrawImage(_dragBitmap, PointToClient(MousePosition));

            EndPerformanceCount(e);
        }
		public override void Draw(TreeNodeAdv node, DrawContext context)
		{
			Graphics g = context.Graphics;
			Rectangle targetRect = new Rectangle(
				context.Bounds.X + this.LeftMargin,
				context.Bounds.Y,
				context.Bounds.Width - this.LeftMargin,
				context.Bounds.Height);

			// Retrieve item information
			PackageItem item = node.Tag as PackageItem;
			if (item == null) return;

			DateTime date = item.ItemPackageInfo.PublishDate;
			bool isOld = (DateTime.Now - date).TotalDays > 180;
			string yearText = date.ToString("yyyy");
			string dayText = date.ToString("MMM dd");

			// Determine layout and drawing info
			SizeF yearTextSize = g.MeasureString(yearText, context.Font);
			SizeF dayTextSize = g.MeasureString(dayText, context.Font);
			Size totalTextSize = new Size(
				(int)Math.Max(yearTextSize.Width, dayTextSize.Width), 
				(int)(yearTextSize.Height + dayTextSize.Height));
			Rectangle yearTextRect = new Rectangle(
				targetRect.X, 
				targetRect.Y + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0), 
				targetRect.Width, 
				(int)yearTextSize.Height);
			Rectangle dayTextRect = new Rectangle(
				targetRect.X, 
				targetRect.Y + (int)yearTextSize.Height + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0), 
				targetRect.Width, 
				targetRect.Height - (int)yearTextSize.Height);
			StringFormat stringFormat = new StringFormat
			{
				Trimming = StringTrimming.EllipsisCharacter, 
				Alignment = StringAlignment.Center, 
				FormatFlags = StringFormatFlags.NoWrap
			};

			// Draw date text
			g.DrawString(yearText, context.Font, new SolidBrush(Color.FromArgb((isOld ? 128 : 255) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), yearTextRect, stringFormat);
			g.DrawString(dayText, context.Font, new SolidBrush(Color.FromArgb((isOld ? 128 : 255) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), dayTextRect, stringFormat);
		}
示例#17
0
        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();
            _dragTimer = new Timer();
            _dragTimer.Interval = 100;
            _dragTimer.Tick += new EventHandler(DragTimerTick);

            _measureContext = new DrawContext();
            _measureContext.Font = Font;
            _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1));

            Input = new NormalInputState(this);
            Search = new IncrementalSearch();
            CreateNodes();
            CreatePens();

            ArrangeControls();

            _plusMinus = new NodePlusMinus();
            _controls = new NodeControlsCollection(this);
        }
 public virtual void Draw(DrawContext context)
 {
     if (Mode == IncrementalSearchMode.Continuous)
     {
         if (!String.IsNullOrEmpty(_searchString) && CurrentNode != null)
         {
             foreach (NodeControlInfo info in Tree.GetNodeControls(CurrentNode))
                 if (info.Control == _selectedControl)
                 {
                     SizeF ms = context.Graphics.MeasureString(_searchString, context.Font);
                     RectangleF rect = info.Bounds;
                     rect.Width = ms.Width;
                     using (Brush backBrush = new SolidBrush(BackColor),
                         fontBrush = new SolidBrush(FontColor))
                     {
                         context.Graphics.FillRectangle(backBrush, rect);
                         context.Graphics.DrawString(_searchString, context.Font, fontBrush, rect);
                     }
                     break;
                 }
         }
     }
 }
示例#19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BeginPerformanceCount();

            DrawContext context = new DrawContext();

            context.Graphics         = e.Graphics;
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            context.Font             = this.Font;
            context.Enabled          = Enabled;

            int y          = 0;
            int gridHeight = 0;

            if (UseColumns)
            {
                DrawColumnHeaders(e.Graphics);
                y += ColumnHeaderHeight;
                // ml: this optimization doesn't work with only small invalid parts.
                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);
                rowRect.Width = displayRect.Width; // by mikel
                gridHeight   += rowRect.Height;
                if (rowRect.Y + y > displayRect.Bottom)
                {
                    break;
                }
                else
                {
                    DrawRow(e, ref context, row, rowRect);
                }
            }

            if ((GridLineStyle & GridLineStyle.Vertical) == GridLineStyle.Vertical)
            {
                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));
            }

            EndPerformanceCount(e);
        }
示例#20
0
		private void DrawIcons()
		{
			using (Graphics gr = Graphics.FromHwnd(this.Handle))
			{
				//Apply the same Graphics Transform logic as used in OnPaint.
				int y = 0;
				if (UseColumns)
				{
					y += ColumnHeaderHeight;
					if (Columns.Count == 0)
						return;
				}
				int firstRowY = _rowLayout.GetRowBounds(FirstVisibleRow).Y;
				y -= firstRowY;
				gr.ResetTransform();
				gr.TranslateTransform(-OffsetX, y);

				DrawContext context = new DrawContext();
				context.Graphics = gr;
				for (int i = 0; i < _expandingNodes.Count; i++)
				{
					foreach (NodeControlInfo item in GetNodeControls(_expandingNodes[i]))
					{
						if (item.Control is ExpandingIcon)
						{
							Rectangle bounds = item.Bounds;
							if (item.Node.Parent == null && UseColumns)
								bounds.Location = Point.Empty; // display root expanding icon at 0,0

							context.Bounds = bounds;
							item.Control.Draw(item.Node, context);
						}
					}
				}
			}
		}
示例#21
0
		protected virtual void OnRowDraw(PaintEventArgs e, TreeNodeAdv node, DrawContext context, int row, Rectangle rowRect)
		{
			if (RowDraw != null)
			{
				TreeViewRowDrawEventArgs args = new TreeViewRowDrawEventArgs(e.Graphics, e.ClipRectangle, node, context, row, rowRect);
				RowDraw(this, args);
			}
		}
        protected override void OnPaint(PaintEventArgs e)
        {
            BeginPerformanceCount();

            DrawContext context = new DrawContext();

            context.Graphics = e.Graphics;
            context.Font     = this.Font;
            context.Enabled  = Enabled;

            int y = 0;

            if (HeaderStyle != ColumnHeaderStyle.None)
            {
                DrawColumnHeaders(e.Graphics);
                y += ColumnHeaderHeight;
                if (Columns.Count == 0 /*|| e.ClipRectangle.Height <= y*/)
                {
                    return;
                }
            }
            y -= _rowLayout.GetRowBounds(FirstVisibleRow).Y;


            e.Graphics.ResetTransform();
            e.Graphics.TranslateTransform(-OffsetX, y);
            Rectangle displayRect = DisplayRectangle;

            for (int row = FirstVisibleRow; row < RowCount; row++)
            {
                Rectangle rowRect = _rowLayout.GetRowBounds(row);
                if (rowRect.Y + y > displayRect.Bottom)
                {
                    break;
                }
                else
                {
                    DrawRow(e, ref context, row, rowRect);
                }
            }

            if (Search.IsActive)
            {
                Search.Draw(context);
            }

            if (_dropPosition.Node != null && DragMode)
            {
                DrawDropMark(e.Graphics);
            }

            e.Graphics.ResetTransform();
            DrawScrollBarsBox(e.Graphics);

            if (DragMode && _dragBitmap != null)
            {
                e.Graphics.DrawImage(_dragBitmap, PointToClient(MousePosition));
            }

            EndPerformanceCount(e);
        }
示例#23
0
 protected Font GetDrawingFont(DrawContext context, string label)
 {
     return(context.Font);
 }
示例#24
0
 public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
 {
     return new Size(this.ParentColumn.Width, this.Parent.RowHeight);
 }
		public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
		{
			return new Size(60, 48);
		}
示例#26
0
		protected Size GetLabelSize(DrawContext context, string label)
		{
			PerformanceAnalyzer.Start("GetLabelSize");

			Font font = GetDrawingFont(context, label);
			Size s = Size.Empty;
			if (UseCompatibleTextRendering)
				s = TextRenderer.MeasureText(label, font);
			else
			{
				SizeF sf = context.Graphics.MeasureString(label, font);
				s = new Size((int)Math.Ceiling(sf.Width), (int)Math.Ceiling(sf.Height));
			}

			PerformanceAnalyzer.Finish("GetLabelSize");

			if (!s.IsEmpty)
				return s;
			else
				return new Size(10, font.Height);
		}
示例#27
0
		protected Font GetDrawingFont(DrawContext context, string label)
		{
			return context.Font;
		}
示例#28
0
 protected Size GetLabelSize(DrawContext context)
 {
     return(GetLabelSize(context, Header));
 }
示例#29
0
        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 (!IsCategoryNode(node))
                {
                    if (node.IsSelected && Focused)
                    {
                        context.DrawSelection = DrawSelectionMode.Active;
                    }
                    else if (node.IsSelected && !Focused && !HideSelection)
                    {
                        context.DrawSelection = DrawSelectionMode.Inactive;
                    }
                }
            }
            context.DrawFocus = Focused && CurrentNode == node;

            OnRowDraw(e, node, context, row, rowRect);

            if (FullRowSelect)
            {
                context.DrawFocus = false;
                if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
                {
                    if (!IsCategoryNode(node))
                    {
                        Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, ClientRectangle.Width, rowRect.Height);
                        if (context.DrawSelection == DrawSelectionMode.Active ||
                            (context.DrawSelection == DrawSelectionMode.Inactive && !HideSelection))
                        {
                            e.Graphics.FillRectangle(SystemBrushes.Highlight, focusRect);
                            context.DrawSelection = DrawSelectionMode.FullRowSelect;
                        }
                        else
                        {
                            e.Graphics.FillRectangle(SystemBrushes.InactiveBorder, focusRect);
                            context.DrawSelection = DrawSelectionMode.None;
                        }
                    }
                    else
                    {
                        var focusRectWidth = ClientRectangle.Width - (_vScrollBar.Visible ? _vScrollBar.Width + 1 : 1);

                        var offsetY         = row == 0 ? rowRect.Y : rowRect.Y + rowRect.Height / 3;
                        var focusRectHeight = row == 0 ? rowRect.Height : rowRect.Height * 2 / 3;
                        var focusRect       = new Rectangle(OffsetX, offsetY, focusRectWidth, focusRectHeight);

                        if (context.DrawSelection == DrawSelectionMode.Active ||
                            (context.DrawSelection == DrawSelectionMode.Inactive && !HideSelection))
                        {
                            DrawRoundedRectangle(e.Graphics, focusRect, 4, new Pen(SystemColors.Highlight));
                            context.DrawSelection = DrawSelectionMode.FullRowSelect;
                        }
                        else
                        {
                            DrawRoundedRectangle(e.Graphics, focusRect, 4, new Pen(SystemColors.InactiveBorder));
                            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 && !IsCategoryNode(node))
            {
                DrawLines(e.Graphics, node, rowRect);
            }

            if (IsCategoryNode(node))
            {
                DrawCategoryTitleUnderline(node.Tree, context, rowRect);
            }

            DrawNode(node, context);
        }
        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)
                {
                    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 (GridLines)
            {
                int x = 0;
                foreach (TreeColumn c in Columns)
                {
                    if (c.IsVisible)
                    {
                        Rectangle rect = new Rectangle(x, rowRect.Y, c.Width, rowRect.Height);
                        e.Graphics.DrawRectangle(SystemPens.InactiveBorder, rect);

                        x += c.Width;
                    }
                }
                if (x < ClientRectangle.Width)
                {
                    Rectangle rect = new Rectangle(x, rowRect.Y, ClientRectangle.Width - x, rowRect.Height);
                    e.Graphics.DrawRectangle(SystemPens.InactiveBorder, rect);
                }
            }


            if (ShowLines)
            {
                DrawLines(e.Graphics, node, rowRect);
            }

            DrawNode(node, context);
        }
示例#31
0
        protected virtual 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;

            // custom draw by mikel
            Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, DisplayRectangle.Width, rowRect.Height);

            context.Bounds = focusRect;
            OnBeforeNodeDrawing(node, context);

            if (FullRowSelect)
            {
                context.DrawFocus = false;
                if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
                {
                    // Handle high contrast mode separately.
                    if (SystemInformation.HighContrast)
                    {
                        // ml: use the highlight color of the system scheme in high contrast mode.
                        using (SolidBrush brush = new SolidBrush(SystemColors.Highlight))
                            e.Graphics.FillRectangle(brush, focusRect);
                    }
                    else
                    {
                        RectangleF bounds = focusRect;
                        bounds.X     += 1.5f;
                        bounds.Y     -= 0.5f;
                        bounds.Width -= 2;
                        bounds.Height--;

                        float        cornerSize = 5;
                        GraphicsPath fillPath   = new GraphicsPath();
                        if (isWin8OrAbove)
                        {
                            fillPath.AddRectangle(bounds);
                        }
                        else
                        {
                            fillPath.AddArc(bounds.Left, bounds.Top, cornerSize, cornerSize, 180, 90);
                            fillPath.AddArc(bounds.Right - cornerSize, bounds.Top, cornerSize, cornerSize, -90, 90);
                            fillPath.AddArc(bounds.Right - cornerSize, bounds.Bottom - cornerSize, cornerSize, cornerSize, 0, 90);
                            fillPath.AddArc(bounds.Left, bounds.Bottom - cornerSize, cornerSize, cornerSize, 90, 90);
                            fillPath.CloseAllFigures();
                        }

                        GraphicsPath outlinePath = new GraphicsPath();
                        bounds.X -= 0.5f;
                        bounds.Y += 0.5f;
                        if (isWin8OrAbove)
                        {
                            outlinePath.AddRectangle(bounds);
                        }
                        else
                        {
                            outlinePath.AddArc(bounds.Left, bounds.Top, cornerSize, cornerSize, 180, 90);
                            outlinePath.AddArc(bounds.Right - cornerSize, bounds.Top, cornerSize, cornerSize, -90, 90);
                            outlinePath.AddArc(bounds.Right - cornerSize, bounds.Bottom - cornerSize, cornerSize, cornerSize, 0, 90);
                            outlinePath.AddArc(bounds.Left, bounds.Bottom - cornerSize, cornerSize, cornerSize, 90, 90);
                            outlinePath.CloseAllFigures();
                        }

                        if (context.DrawSelection == DrawSelectionMode.Active)
                        {
                            if (isWin8OrAbove)
                            {
                                using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xFF, 0xD1, 0xE8, 0xFF)))
                                    e.Graphics.FillPath(brush, fillPath);
                                using (Pen pen = new Pen(Color.FromArgb(255, 0x6E, 0xC0, 0xE7)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }
                            else
                            {
                                using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
                                           new PointF(0, bounds.Top),
                                           new PointF(0, bounds.Bottom),
                                           Color.FromArgb(255, 0xF1, 0xF7, 0xFE),
                                           Color.FromArgb(255, 0xCF, 0xE4, 0xFE)))
                                    e.Graphics.FillPath(gradientBrush, fillPath);

                                using (Pen pen = new Pen(Color.FromArgb(255, 0x83, 0xAC, 0xDD)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }

                            context.DrawSelection = DrawSelectionMode.FullRowSelect;
                        }
                        else
                        {
                            if (isWin8OrAbove)
                            {
                                using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xFF, 0xF7, 0xF7, 0xF7)))
                                    e.Graphics.FillPath(brush, fillPath);
                                using (Pen pen = new Pen(Color.FromArgb(0xFF, 0xDE, 0xDE, 0xDE)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }
                            else
                            {
                                using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
                                           new PointF(0, bounds.Top),
                                           new PointF(0, bounds.Bottom),
                                           Color.FromArgb(255, 0xF8, 0xF8, 0xF8),
                                           Color.FromArgb(255, 0xE5, 0xE5, 0xE5)))
                                    e.Graphics.FillPath(gradientBrush, fillPath);

                                using (Pen pen = new Pen(Color.FromArgb(255, 0xD9, 0xD9, 0xD9)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }

                            context.DrawSelection = DrawSelectionMode.None;
                        }
                    }
                }
            }

            // by mikez, mikel
            if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal)
            {
                e.Graphics.DrawLine(_gridPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
            }

            if (ShowLines)
            {
                DrawLines(e.Graphics, node, rowRect);
            }

            DrawNode(node, context);

            // ml: added for overlay images.
            OnAfterNodeDrawing(node, context);
        }
示例#32
0
        private void ResizeViewColumns()
        {
            if (!_treeContainer.TreeRootStorageUnits.Any()) return;
            var measureContext = new DrawContext
            {
                Graphics = Graphics.FromImage(new Bitmap(1, 1)),
                Font = TreeViewAdv_Files.Font
            };

            // On the first column take head for the plus/minus and lines. The 7 is the LeftMargin of the PlusMinus.
            int newWidth = (TreeViewAdv_Files.ShowPlusMinus ? 20 : 0) + 7;
            foreach (var column in TreeViewAdv_Files.Columns)
            {
                foreach (var nodeControl in TreeViewAdv_Files.NodeControls)
                {
                    if (nodeControl.ParentColumn != column) continue;
                    // Many controls can be displayed in the same column
                    int maxControlWidth = 0;
                    foreach (var nodeAdv in TreeViewAdv_Files.AllNodes)
                    {
                        var size = nodeControl.MeasureSize(nodeAdv, measureContext);
                        maxControlWidth = Math.Max(maxControlWidth, (size.Width + nodeControl.LeftMargin));
                    }
                    newWidth += maxControlWidth;
                }
                column.Width = newWidth;
                newWidth = 0;
            }
        }
示例#33
0
 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 TreeViewRowDrawEventArgs(Graphics graphics, Rectangle clipRectangle, TreeNodeAdv node, DrawContext context, int row, Rectangle rowRect)
     : base(graphics, clipRectangle)
 {
     _node    = node;
     _context = context;
     _row     = row;
     _rowRect = rowRect;
 }
		public override void Draw(TreeNodeAdv node, DrawContext context)
		{
			Graphics g = context.Graphics;
			Rectangle targetRect = new Rectangle(
				context.Bounds.X + this.LeftMargin,
				context.Bounds.Y,
				context.Bounds.Width - this.LeftMargin,
				context.Bounds.Height);

			// Retrieve item information
			PackageItem item = node.Tag as PackageItem;
			if (item == null) return;

			Version itemVersion = null;
			Version newVersion = null;
			PackageCompatibility compatibility = PackageCompatibility.None;
			bool highlightItemVersion = item is LocalPackageItem;
			bool isInstalled = false;
			bool isUpToDate = false;
			if (item != null)
			{
				isInstalled = item.InstalledPackageInfo != null;
				compatibility = item.Compatibility;

				if (item.InstalledPackageInfo != null)
					itemVersion = item.InstalledPackageInfo.Version;
				else if (item.ItemPackageInfo != null)
					itemVersion = item.ItemPackageInfo.Version;

				if (item.NewestPackageInfo != null)
					newVersion = item.NewestPackageInfo.Version;

				if (itemVersion != null && newVersion != null)
					isUpToDate = itemVersion >= newVersion;
			}
			string itemVersionText = PackageManager.GetDisplayedVersion(itemVersion);
			string newVersionText = isInstalled && !isUpToDate ? PackageManager.GetDisplayedVersion(newVersion) : string.Empty;

			// Determine background color and icon based on versioning
			Brush backgroundBrush = null;
			Image icon = null;
			if (isInstalled) backgroundBrush = new SolidBrush(Color.FromArgb(32, 128, 128, 128));
			if (newVersion != null && itemVersion != null)
			{
				if (isInstalled)
				{
					if (newVersion <= itemVersion)
						icon = Properties.PackageManagerFrontendResCache.IconUpToDate;
					else if (compatibility == PackageCompatibility.Definite)
						icon = Properties.PackageManagerFrontendResCache.IconSafeUpdate;
					else if (compatibility == PackageCompatibility.Likely)
						icon = Properties.PackageManagerFrontendResCache.IconLikelySafeUpdate;
					else if (compatibility == PackageCompatibility.Unlikely)
						icon = Properties.PackageManagerFrontendResCache.IconLikelyUnsafeUpdate;
					else if (compatibility == PackageCompatibility.None)
						icon = Properties.PackageManagerFrontendResCache.IconIncompatibleUpdate;
				}
				else
				{
					if (compatibility == PackageCompatibility.Unlikely)
						icon = Properties.PackageManagerFrontendResCache.IconLikelyUnsafeInstall;
					else if (compatibility == PackageCompatibility.None)
						icon = Properties.PackageManagerFrontendResCache.IconIncompatibleInstall;
				}
			}

			// Calculate drawing layout and data
			StringFormat stringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, Alignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap };
			Rectangle currentVersionRect;
			Rectangle newestVersionRect;
			Rectangle iconRect;
			{
				SizeF currentVersionSize;
				SizeF newestVersionSize;
				Size iconSize;
				// Base info
				{
					newestVersionSize = g.MeasureString(newVersionText, context.Font, targetRect.Width, stringFormat);
					currentVersionSize = g.MeasureString(itemVersionText, context.Font, targetRect.Width, stringFormat);
					iconSize = icon != null ? icon.Size : Size.Empty;
				}
				// Alignment info
				{
					Size totalTextSize = new Size(
						(int)Math.Max(currentVersionSize.Width, newestVersionSize.Width), 
						(int)(currentVersionSize.Height + newestVersionSize.Height));
					int leftSpacing = (targetRect.Width - totalTextSize.Width - iconSize.Width - 4) / 2;
					int iconIndent = iconSize.Width + 4 + leftSpacing;

					iconRect = new Rectangle(
						targetRect.X + leftSpacing,
						targetRect.Y + targetRect.Height / 2 - iconSize.Height / 2,
						iconSize.Width,
						iconSize.Height);
					newestVersionRect = new Rectangle(
						targetRect.X + iconIndent, 
						targetRect.Y + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0), 
						targetRect.Width - iconIndent, 
						(int)newestVersionSize.Height);
					currentVersionRect = new Rectangle(
						targetRect.X + iconIndent, 
						targetRect.Y + (int)newestVersionSize.Height + Math.Max((targetRect.Height - totalTextSize.Height) / 2, 0), 
						targetRect.Width - iconIndent, 
						targetRect.Height - (int)newestVersionSize.Height);
				}
			}

			// Draw background and version texts
			if (backgroundBrush != null)
			{
				g.FillRectangle(backgroundBrush, targetRect);
			}
			if (icon != null)
			{
				g.DrawImageUnscaledAndClipped(icon, iconRect);
			}
			{
				bool bothVisible = !string.IsNullOrWhiteSpace(itemVersionText) && !string.IsNullOrWhiteSpace(newVersionText);
				highlightItemVersion = highlightItemVersion || !bothVisible;
				g.DrawString(newVersionText, context.Font, new SolidBrush(Color.FromArgb((highlightItemVersion ? 128 : 255) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), newestVersionRect, stringFormat);
				g.DrawString(itemVersionText, context.Font, new SolidBrush(Color.FromArgb((highlightItemVersion ? 255 : 128) / (context.Enabled ? 1 : 2), this.Parent.ForeColor)), currentVersionRect, stringFormat);
			}
		}
示例#36
0
        public TreeViewAdv()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint
                     | ControlStyles.UserPaint
                     | ControlStyles.OptimizedDoubleBuffer
                     | ControlStyles.ResizeRedraw
                     | ControlStyles.Selectable
                     , true);


            if (Environment.OSVersion.Version.Major < 6)
            {
                if (Application.RenderWithVisualStyles)
                {
                    _columnHeaderHeight = 20;
                }
                else
                {
                    _columnHeaderHeight = 17;
                }
            }
            else
            {
                if (Application.RenderWithVisualStyles)
                {
                    _columnHeaderHeight = 25;
                }
                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(this);
            _controls  = new NodeControlsCollection(this);

            Font = _font;
            ExpandingIcon.IconChanged += ExpandingIconChanged;
        }
示例#37
0
        private void CreateDragBitmap(IDataObject data)
        {
            if (UseColumns || !DisplayDraggingNodes)
                return;

            TreeNodeAdv[] nodes = data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
            if (nodes != null && nodes.Length > 0)
            {
                Rectangle rect = DisplayRectangle;
                Bitmap bitmap = new Bitmap(rect.Width, rect.Height);
                using (Graphics gr = Graphics.FromImage(bitmap))
                {
                    gr.Clear(BackColor);
                    DrawContext context = new DrawContext();
                    context.Graphics = gr;
                    context.Font = Font;
                    context.Enabled = true;
                    int y = 0;
                    int maxWidth = 0;
                    foreach (TreeNodeAdv node in nodes)
                    {
                        if (node.Tree == this)
                        {
                            int x = 0;
                            int height = _rowLayout.GetRowBounds(node.Row).Height;
                            foreach (NodeControl c in NodeControls)
                            {
                                Size s = c.GetActualSize(node, context);
                                if (!s.IsEmpty)
                                {
                                    int width = s.Width;
                                    rect = new Rectangle(x, y, width, height);
                                    x += (width + 1);
                                    context.Bounds = rect;
                                    c.Draw(node, context);
                                }
                            }
                            y += height;
                            maxWidth = Math.Max(maxWidth, x);
                        }
                    }

                    if (maxWidth > 0 && y > 0)
                    {
                        _dragBitmap = new Bitmap(maxWidth, y, PixelFormat.Format32bppArgb);
                        using (Graphics tgr = Graphics.FromImage(_dragBitmap))
                            tgr.DrawImage(bitmap, Point.Empty);
                        BitmapHelper.SetAlphaChanelValue(_dragBitmap, 150);
                    }
                    else
                        _dragBitmap = null;
                }
            }
        }
        private void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect)
        {
            TreeNodeAdv node = RowMap[row];

            if (node.IsHidden)
            {
                return;
            }
            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 || !InactiveSelection))
                {
                    context.DrawSelection = DrawSelectionMode.Active;
                }
                else if (node.IsSelected && !Focused && !HideSelection)
                {
                    context.DrawSelection = DrawSelectionMode.Inactive;
                }
            }
            context.DrawFocus = Focused && CurrentNode == node;

            OnRowDraw(e, node, context, row, rowRect);

            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(new SolidBrush(_fullRowSelectActiveColor), focusRect);
                        context.DrawSelection = DrawSelectionMode.FullRowSelect;
                    }
                    else
                    {
                        e.Graphics.FillRectangle(new SolidBrush(_fullRowSelectInactiveColor), 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);
        }
示例#39
0
        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;

            OnRowDraw(e, node, context, row, rowRect);

            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);
        }
示例#40
0
 protected virtual void OnBeforeNodeDrawing(TreeNodeAdv node, DrawContext context)
 {
     if (BeforeDrawNode != null)
     BeforeDrawNode(this, new TreeViewAdvDrawRowEventArgs(node, context));
 }
示例#41
0
 public Size MeasureSize(DrawContext context)
 {
     return(GetLabelSize(context));
 }
示例#42
0
        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);
        }