Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Change font of RadTreeView e.a.

Not answered Change font of RadTreeView e.a.

Feed from this thread
  • Lucien avatar

    Posted on Oct 21, 2011 (permalink)

    Hi,

    I am trying the do a few things and I don't seem to be able to do this with the WinForms RadTreeView control - or at least I don't know how:

    1. Change the font. Seems simple, but I tried doing it in both the designer and in code (myTreeView.Font = new Font(...) etc), but no matter what I set it to, the treeview still shows the same font. What do I need to do to change this??

    2. How to I remove/hide/decrease the left margin showing on all first level nodes? I am not using a root node and there's always a white margin to the left of each node.

    Thanks!

    Lucien Dol
    New Zealand.

    Reply

  • Stefan Stefan admin's avatar

    Posted on Oct 26, 2011 (permalink)

    Hello Lucien,

    Thank you for writing.

    You can achieve both of your requirements by handling the NodeFormatting event of RadTreeView. Here is a code snippet, which sets the Font of the ContentElement of the node, and also hides the LinesContainerElement, which is responsible for the lines in hierarchical trees and also it causing the space on the left side of the node:
    Font f = new Font("Arial", 14);
    void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
    {
        //remove the lines container to reduce the space on the left of the nodes
        e.NodeElement.LinesContainerElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        //set font
        e.NodeElement.ContentElement.Font = f;
    }

    More information regarding node formatting, can be found in the following documentation article: http://www.telerik.com/help/winforms/treeview-working-with-nodes-formatting-nodes.html.

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us. 

    All the best,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

    Reply

  • Lucien avatar

    Posted on Nov 4, 2011 (permalink)

    Thanks. That fixed the problem. If have modified it somewhat to ensure the lines (and the space for the lines) only disappear when it is a root node:

    private void sitesTreeView_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)

    {

    var font = new Font("Microsoft Sans Serif", 10);

    e.NodeElement.ContentElement.Font = font;

    if(e.NodeElement.IsRootNode)

    e.NodeElement.LinesContainerElement.Visibility = ElementVisibility.Collapsed;

    }


    Lucien.

    Reply

  • Stefan Stefan admin's avatar

    Posted on Nov 9, 2011 (permalink)

    Hello Lucien,

    I am glad that I could help. Just one suggestion, place the initialization of the font outside of the NodeFormatting event handler, since this event is fired constantly and the current implementation may cause performance issues. 
     
    Regards,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Treeview > Change font of RadTreeView e.a.
Related resources for "Change font of RadTreeView e.a."

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]