was ich an dem punkt nicht verstehe ist das die anzeige nach ausführen von UpdateSingleNode auch tatsächlich sofort aktualisiert ist! Irgentwie hab ich immer gedacht man müsste dem control bzw win explizit mitteilen das sich was geändert hat?!
const int TV_FIRST = 0x1100;
const int TVM_GETITEMRECT = (TV_FIRST + 4);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
private void UpdateSingleNode(TreeNode node)
{
if (node.IsVisible)
{
RECT rc;
unsafe
{
*(void**)&rc = node.Handle.ToPointer();
SendMessage(Handle, TVM_GETITEMRECT, IntPtr.Zero, new IntPtr(&rc));
}
// dc der treeview holen
using (Graphics dc = Graphics.FromHwnd(Handle))
{
// erstelle set mit atm verarbeiteten states
TreeNodeStates states = TreeNodeStates.Default;
states |= node.IsSelected ? TreeNodeStates.Selected : TreeNodeStates.Default;
// sende ondrawnode
OnDrawNode(new DrawTreeNodeEventArgs(dc, node, rc.ToRectangle(), states));
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
int _left;
int _top;
int _right;
int _bottom;
public RECT(global::System.Drawing.Rectangle rectangle)
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
{
}
public RECT(int left, int top, int right, int bottom)
{
_left = left;
_top = top;
_right = right;
_bottom = bottom;
}
public int X
{
get { return Left; }
set { Left = value; }
}
public int Y
{
get { return Top; }
set { Top = value; }
}
public int Left
{
get { return _left; }
set { _left = value; }
}
public int Top
{
get { return _top; }
set { _top = value; }
}
public int Right
{
get { return _right; }
set { _right = value; }
}
public int Bottom
{
get { return _bottom; }
set { _bottom = value; }
}
public int Height
{
get { return Bottom - Top; }
set { Bottom = value - Top; }
}
public int Width
{
get { return Right - Left; }
set { Right = value + Left; }
}
public global::System.Drawing.Point Location
{
get { return new global::System.Drawing.Point(Left, Top); }
set
{
Left = value.X;
Top = value.Y;
}
}
public global::System.Drawing.Size Size
{
get { return new global::System.Drawing.Size(Width, Height); }
set
{
Right = value.Width + Left;
Bottom = value.Height + Top;
}
}
public global::System.Drawing.Rectangle ToRectangle()
{
return new global::System.Drawing.Rectangle(this.Left, this.Top, this.Width, this.Height);
}
public static global::System.Drawing.Rectangle ToRectangle(RECT Rectangle)
{
return Rectangle.ToRectangle();
}
public static RECT FromRectangle(global::System.Drawing.Rectangle Rectangle)
{
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
}
}