Unplanned
Last Updated: 30 Mar 2016 13:34 by ADMIN
ADMIN
George
Created on: 11 Jun 2014 11:43
Category: TreeView
Type: Bug Report
0
FIX. RadTreeView - setting the font of the nodes to Tahoma 13pt results in a thick black font on Windows 7 and Vista when ClearType is turned off
To reproduce:

Add some notes to RadTreeView. Set the Font as follows in the NodeFormatting event:

Font font = new Font("Tahoma", 13f);
void tree_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    e.NodeElement.ContentElement.Font = font;
}

Start the project on Windows 7 or Vista with ClearType off and you will see that the font is thick. 

Workaround:

Use the following node element:

public class MyTreeNodeElement : TreeNodeElement
{
    protected override TreeNodeContentElement CreateContentElement()
    {
        return new MyTreeNodeContentElement();
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(TreeNodeElement);
        }
    }
}

public class MyTreeNodeContentElement : TreeNodeContentElement
{
    protected override void PrePaintElement(Telerik.WinControls.Paint.IGraphics graphics)
    {
        base.PrePaintElement(graphics);

        Graphics g = graphics.UnderlayGraphics as Graphics;

        if (g == null)
        {
            return;
        }

        if (this.Enabled)
        {
            g.TextRenderingHint = this.TextRenderingHint;
        }
        else
        {
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        }
    }
}

void tree_CreateNodeElement(object sender, CreateTreeNodeElementEventArgs e)
{
    e.NodeElement = new MyTreeNodeElement();
}

And set the TextRenderingHint of the ContentElement:

Font font = new Font("Tahoma", 13f);
void tree_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    e.NodeElement.ContentElement.Font = font;
    e.NodeElement.ContentElement.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
}

0 comments