The full framework TreeView control supports setting a Font on a per-node basis, the Compact Framework control doesn't support this, however with a little interop magic you can mark individual nodes as Bold. Because the .NETCF v2.0 TreeView control exposes it's own window handle, and each TreeNode also exposes it's handle, we have all the raw data we need to format the node. First we need to define a structure and a couple of enumerations:-
internal struct TVITEM { public TVIF mask; public IntPtr hItem; public TVIS state; public TVIS stateMask; [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]string pszText; int cchTextMax; int iImage; int iSelectedImage; int cChildren; int lParam; }[Flags()]internal enum TVIF{TEXT =0x0001,IMAGE =0x0002,PARAM =0x0004,STATE =0x0008,HANDLE =0x0010,SELECTEDIMAGE =0x0020,CHILDREN =0x0040,}[Flags()]internal enum TVIS{SELECTED =0x0002,CUT =0x0004,DROPHILITED =0x0008,BOLD =0x0010,EXPANDED =0x0020,EXPANDEDONCE =0x0040,EXPANDPARTIAL =0x0080,OVERLAYMASK =0x0F00,STATEIMAGEMASK =0xF000,USERMASK =0xF000,}
Then I've created a single static method which can set the bold state of any node:-
public static void SetNodeEmphasis(TreeNode n, bool bold){//get the control and node handlesIntPtr hTreeview = n.TreeView.Handle;IntPtr hNode = n.Handle;//create a TVITEM structTVITEM t = new TVITEM();t.hItem = hNode;//mark only the handle and state members as validt.mask = TVIF.HANDLE | TVIF.STATE;//set the state to bold if bold param was truet.state = bold ? TVIS.BOLD : 0;//set statemask to show we want to set the bold statet.stateMask = TVIS.BOLD;//pin the struct in memoryGCHandle hTVITEM = GCHandle.Alloc(t, GCHandleType.Pinned);//create a TVM_SETITEM message with the handle of our pinned structMicrosoft.WindowsCE.Forms.Message m = Microsoft.WindowsCE.Forms.Message.Create(hTreeview, 0x113F, IntPtr.Zero, hTVITEM.AddrOfPinnedObject());//send the message to the treeviewMicrosoft.WindowsCE.Forms.MessageWindow.SendMessage(ref m);//free the pinned structurehTVITEM.Free();}
The method is easy to reuse as you only need to pass the TreeNode in, it will grab the handle of the parent control from the node itself. After applying the formatting to a couple of nodes you'll get something like this:-
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.