J
Jon Slaughter
I'm trying to override the default paiting of a treeview but I get bad
results:
My code(well, atleast this is the most simple that reproduces the result) is
this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}
My code to turn this on is
DirTView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
DirTView.DrawNode += new
DrawTreeNodeEventHandler((DrawTreeNodeEventHandler)TVDrawNode);
Now the problem is that the method TVDrawNode gets called many times to
print the nodes more than once. Sometimes its called with the correct Bounds
and other times Bounds is 0 resulting the the Text for each node being
printed at the upper left corner resulting in a mishmash of text. It does
print correctly though the "second" time through and it only seems to do
this on grandchildren. (I have a parent, a child and an several
grandchildren.)
When I expand the child is when it occures and the first row contains all
the text's for all the nodes while the rest of the nodes are fine. This
means its getting called to draw the node more than once and one of those
times the Bounds is not set properly.
What the heck is going on? Its very frustrating doing this stuff because I
can't seem to find any help on the subject ;/ MSDN is pitiful at describing
how these things work... atleast I can't find anything there that goes into
any more detail than just the descriptions of methods and fields.
Is there something I'm obviously doing wrong?
(I'm not creating a custom treeview control either but just overriding the
"paint" method for the nodes in my app)
Thanks,
Jon
results:
My code(well, atleast this is the most simple that reproduces the result) is
this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}
My code to turn this on is
DirTView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
DirTView.DrawNode += new
DrawTreeNodeEventHandler((DrawTreeNodeEventHandler)TVDrawNode);
Now the problem is that the method TVDrawNode gets called many times to
print the nodes more than once. Sometimes its called with the correct Bounds
and other times Bounds is 0 resulting the the Text for each node being
printed at the upper left corner resulting in a mishmash of text. It does
print correctly though the "second" time through and it only seems to do
this on grandchildren. (I have a parent, a child and an several
grandchildren.)
When I expand the child is when it occures and the first row contains all
the text's for all the nodes while the rest of the nodes are fine. This
means its getting called to draw the node more than once and one of those
times the Bounds is not set properly.
What the heck is going on? Its very frustrating doing this stuff because I
can't seem to find any help on the subject ;/ MSDN is pitiful at describing
how these things work... atleast I can't find anything there that goes into
any more detail than just the descriptions of methods and fields.
Is there something I'm obviously doing wrong?
(I'm not creating a custom treeview control either but just overriding the
"paint" method for the nodes in my app)
Thanks,
Jon