6

ツリービューがあり、ツリービューのアイテムに基づいて、右側にリストビューがあります。SO ほとんどの UI は、Windows Explorer のような外観です。だから今私が直面している問題は、右側に来るリストビューから多数のオブジェクトを削除すると、左側のツリービューが部分的にペイントされた(私が言える小さな部分).VS IDEからCLR例外を添付すると、それは行 sampletree.EndUpdate(); メモリ不足を除いて。リストビューに次の項目を追加すると、すべてが正常になります。ツリービューが完全にペイントされていることを意味します。例外が発生しています

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()

私のツリービューが小さな部分だけをペイントし、連続した変更が完全にペイントされる理由を知っていますか? コードスニペットを以下に示しますe

 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
       }
    }

更新 私はこのようにフォントを使用しています

case State.Modified:
                     NodeFont = new Font(TreeView.Font, FontStyle.Bold);
break;

それは問題になりますか

4

3 に答える 3

1

私はまったく同じ問題にぶつかりました。XP 以降の Windows システムでのみ発生するようで、BeginUpdate()andEndUpdate()呼び出しを削除すると発生しません。

BeginUpdate()したがって、回避策として、 andEndUpdate()呼び出しを削除してみてください。これは、ノードの更新中に視覚的なカクつきが発生する可能性があることを意味しますが、プラス面として、クラッシュすることはありません。それは確かにネットの勝利です。

この問題に対処する MSDN/Connect には何も見つかりませんでした。現在、自己完結型のテスト ケースをまとめる時間はありませんが、それ以降のバージョンで TreeViews の一括更新を処理する際のバグだと思います。 Windowsの。

于 2013-05-01T09:45:23.063 に答える