From cb386ead2a2ddc17eab7262d36a6b6d6d42b40d9 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Tue, 19 Aug 2008 18:41:20 +0000 Subject: [PATCH] Fixed a null reference exception that occurred when opening the Component Inspector in a release build. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3427 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Src/Controls/TreeListPanel.cs | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/src/AddIns/Misc/ComponentInspector/ComponentInspector.Core/Src/Controls/TreeListPanel.cs b/src/AddIns/Misc/ComponentInspector/ComponentInspector.Core/Src/Controls/TreeListPanel.cs index 0813addb0f..700a929faf 100644 --- a/src/AddIns/Misc/ComponentInspector/ComponentInspector.Core/Src/Controls/TreeListPanel.cs +++ b/src/AddIns/Misc/ComponentInspector/ComponentInspector.Core/Src/Controls/TreeListPanel.cs @@ -8,6 +8,7 @@ using System; using System.Collections; using System.Drawing; +using System.Runtime.InteropServices; using System.Windows.Forms; using ICSharpCode.Core; @@ -26,11 +27,12 @@ namespace NoGoop.Controls internal ArrayList _columnHeaderPanels; internal ArrayList _columnHeaderSplitters; protected int _scrollPos; - protected static IntPtr _greyPen; + protected static Pen _greyPen; static TreeListPanel() { - _greyPen = Windows.CreatePen(Windows.PS_SOLID, 1, Windows.GREY); + SolidBrush brush = new SolidBrush(Color.LightGray); + _greyPen = new Pen(brush, 1); } public TreeListPanel() @@ -127,47 +129,31 @@ namespace NoGoop.Controls internal void HandleColumnsDrawing(TreeListNode tlNode, NMCUSTOMDRAW cd) { - IntPtr oldPos; RECT newRect = cd.rc; // Make text align correctly - seems to be off a pixel newRect.top += 1; - // Do each of the columns defined for the tree - for (int i = 0; i < _treeView.Columns.Count; i++) { - newRect.left = cd.rc.left + ((Splitter)_columnHeaderSplitters[i]).Bounds.X - _scrollPos; - Object colData = tlNode.ColumnData[i]; - if (i == 0) { - // Clear out the data for the column (first time) - Windows.SelectObject(cd.hdc, - Windows.GetSysColorBrush - (Windows.SYSCOLOR_WINDOW)); - Windows.SelectObject(cd.hdc, - Windows.GetStockObject - (Windows.WHITE_PEN)); - // Clear out where all of the columns go; start a little - // before the line - Windows.Rectangle(cd.hdc, - newRect.left - PIXEL_PADDING, - cd.rc.top, - cd.rc.right, - cd.rc.bottom); - // Set up for drawing grey lines - Windows.SelectObject(cd.hdc, _greyPen); - } - // Vertical line to separate the columns - Windows.MoveToEx(cd.hdc, newRect.left, cd.rc.top, out oldPos); - Windows.LineTo(cd.hdc, newRect.left, cd.rc.bottom); - // Write the actual text - if (colData != null) { - // Start the text one pixel after the line - newRect.left += PIXEL_PADDING; - Windows.DrawText(cd.hdc, colData.ToString(), -1, ref newRect, 0); + using (Graphics g = Graphics.FromHdc(cd.hdc)) { + // Do each of the columns defined for the tree + for (int i = 0; i < _treeView.Columns.Count; i++) { + newRect.left = cd.rc.left + ((Splitter)_columnHeaderSplitters[i]).Bounds.X - _scrollPos; + Object colData = tlNode.ColumnData[i]; + if (i == 0) { + // Clear out the data for the column (first time) + g.FillRectangle(SystemBrushes.Window, newRect.left - PIXEL_PADDING, cd.rc.top, cd.rc.right, cd.rc.bottom); + } + // Vertical line to separate the columns + g.DrawLine(_greyPen, newRect.left, cd.rc.top, newRect.left, cd.rc.bottom); + // Write the actual text + if (colData != null) { + // Start the text one pixel after the line + newRect.left += PIXEL_PADDING; + g.DrawString(colData.ToString(), _treeView.Font, SystemBrushes.ControlText, newRect.left, newRect.top); + } } + // Draw the horizontal grid lines + g.DrawLine(_greyPen, cd.rc.left, cd.rc.top, cd.rc.right, cd.rc.top); + g.DrawLine(_greyPen, cd.rc.left, cd.rc.bottom, cd.rc.right, cd.rc.bottom); } - // Draw the horizontal grid lines - Windows.MoveToEx(cd.hdc, cd.rc.left, cd.rc.top, out oldPos); - Windows.LineTo(cd.hdc, cd.rc.right, cd.rc.top); - Windows.MoveToEx(cd.hdc, cd.rc.left, cd.rc.bottom, out oldPos); - Windows.LineTo(cd.hdc, cd.rc.right, cd.rc.bottom); } protected override void WndProc(ref Message m)