Tony <yo***@perigee.net> wrote:
Here is the main() from a straight new "Windows Application" Project.
For future reference, it's much more helpful if you really *would* post
the complete code - it takes a lot longer to open up VS.NET, find a
throwaway solution, add a project, run the test and then delete the
project and all the files within it than to just edit and compile a
single text file.
In this case, the test code can be reduced to:
using System;
using System.Drawing;
using System.Windows.Forms;
class Test
{
static void Main()
{
Form f1 = new Form();
TreeNode tnNewChild = new TreeNode
("New Child Node Text is Cut Off, BTW");
Font oldFont = tnNewChild.NodeFont;
// runtime error (THIS IS THE ONE I NEED TO WORK):
tnNewChild.NodeFont = new Font
(oldFont,System.Drawing.FontStyle.Bold);
}
}
And the reason is simple: oldFont is null. As the docs for
TreeNode.NodeFont say:
<quote>
If a null reference (Nothing in Visual Basic), the Font used is the
Font property value of the TreeView control that this node is attached
to.
</quote>
So it's perfectly reasonable for it to be null - but you can't create a
new font based on nothing.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too