我有一個樹視圖和基於TreeView的項目,我有右側的列表視圖。所以幾乎UI是我們的Windows資源管理器的外觀。所以現在我面臨的問題是,當我從列表視圖中刪除大量的對象來到右側時,左側的樹視圖變成部分畫(我可以說小部分)。當我從VS IDE獲得CLR excpetion時,它指向line sampletree.EndUpdate();除了內存不足之外。當我加入的ListView一切下一個項目都正常我的意思是樹狀完全畫 異常我得到是.net中的內存異常winform treeview
System.OutOfMemoryException occurred
Message=Out of memory.
Source=System.Drawing
StackTrace:
at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
at System.Drawing.Font.ToLogFont(Object logFont)
at System.Drawing.Font.ToHfont()
at System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
at System.Windows.Forms.OwnerDrawPropertyBag.get_FontHandle()
at System.Windows.Forms.TreeView.CustomDraw(Message& m)
at System.Windows.Forms.TreeView.WmNotify(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmNotify(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control.EndUpdateInternal(Boolean invalidate)
at System.Windows.Forms.TreeView.EndUpdate()
你有我爲什麼我的TreeView的是隻塗一個samll一部分,並連續修改油漆充分的任何想法?代碼片段顯示belowe
if((values != null) &&
(values .OverallState != ToBeDeleted) &&
(values .OverallState != .Deleted))
{
TreeView tree = this.TreeView;
if(tree != null)
{
tree.BeginUpdate();
}
TryUpdate();
TryPopulate();
if(tree != null)
{
tree.EndUpdate(); // here exception coming
}
}
UPDATE 我使用的字體像這樣
case State.Modified:
NodeFont = new Font(TreeView.Font, FontStyle.Bold);
break;
這是否漏水GDI資源使
做的winform樹視圖有任何已知的問題,或者任何索引變成-1? – vettori 2013-04-22 13:46:52
同樣的問題在這裏。任務管理器顯示該進程創建了10,000個GDI字體句柄(然後崩潰,最大值爲10,000)。只有當我同時創建很多節點時纔會發生這種情況。 – dacap 2013-07-11 17:10:38