Thursday, April 16, 2009

TreeView Bug with Bold Fonts

In a .Net 2.0 Windows forms app, if you can’t get the a TreeNode to be displayed as bold within a TreeView, take a look at this KB article:

The text of a node may be truncated when you programmatically set the Font property of the node to the Bold value in a Windows Forms-based application that uses the .NET Framework 2.0
http://support.microsoft.com/?scid=kb;en-us;937215&x=8&y=13

You have to modify the "Text" property of the Node after it has been added to the TreeView.

Thursday, February 12, 2009

Flickering ListView

If you have a ListView in a Windows Forms app, use the following code to stop it from flickering:

using System.Reflection;

// For some reason the "DoubleBuffered" property isn't exposed on the ListView class
// so we have to use reflection to set it even though it's a "protected" property...

PropertyInfo oDoubleBuffered = this.listView1.GetType().GetProperty(
"DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance );
if ( oDoubleBuffered != null )
oDoubleBuffered.SetValue( this.listView1, true, null );

Sunday, January 4, 2009

Temporary Assemblies with XmlSerializer

If you are using the XmlSerializer in your app, these pages might help you with some scalability problems:

Scott Hanselman's Computer Zen - Changing where XmlSerializer Outputs Temporary Assemblies
http://www.hanselman.com/blog/ChangingWhereXmlSerializerOutputsTemporaryAssemblies.aspx

Scott Hanselman's Computer Zen - HOW TO Debug into a .NET XmlSerializer Generated Assembly http://www.hanselman.com/blog/HOWTODebugIntoANETXmlSerializerGeneratedAssembly.aspx

Also, make sure that you cache the XmlSerializer class that gets generated for your type.  Each time a serializer class gets generated, it gets compiled into a separate assembly and loaded into your AppDomain.  The problem is that assemblies can not be unloaded from an AppDomain so it just fills up with these generated assemblies.