I do the following: I set the DrawNode event to call, it sets the node in bold and deletes the highlighted color.
You can set any color you like using the first parameter of the e.Graphics.FillRectangle function.
private void SetNodeBoldWhenSelected(object sender, DrawTreeNodeEventArgs e) { if (e.Node == null) return; var font = e.Node.NodeFont ?? e.Node.TreeView.Font; if (e.Node.IsSelected) { font = new Font(font, FontStyle.Bold); } var bounds = new Rectangle( e.Bounds.X,e.Bounds.Y,e.Bounds.Width+20,e.Bounds.Height); e.Graphics.FillRectangle(SystemBrushes.ControlDarkDark, bounds); TextRenderer.DrawText(e.Graphics, e.Node.Text, font, bounds, SystemColors.HighlightText, TextFormatFlags.GlyphOverhangPadding); }
Now, when I select node, I get 20 pixels more space, for my font it works well, you can calculate the required "real" size, but there is no specification indicating that this is necessary, but you can use Graphics.MeasureString if you consider what you need to do it.
Computer Trading Nov 22 '17 at 13:37 2017-11-22 13:37
source share