Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:38:58+00:00 2026-06-16T02:38:58+00:00

I have a TreeView and each of it’s Node.Text has two words. The first

  • 0

I have a TreeView and each of it’s Node.Text has two words.
The first and second words should have different colors. I’m already changing the color of the text with the DrawMode properties and the DrawNode event but I can’t figure out how to split the Node.Text in two different colors. Someone pointed out I could use TextRenderer.MeasureText but I have no idead how/where to use it.

Someone has an idea ?


Code :

formload()
{
  treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
}

private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e) 
{
Color nodeColor = Color.Red;
if ((e.State & TreeNodeStates.Selected) != 0)
  nodeColor = SystemColors.HighlightText;

 TextRenderer.DrawText(e.Graphics,
                    e.Node.Text,
                    e.Node.NodeFont,
                    e.Bounds,
                    nodeColor,
                    Color.Empty,
                    TextFormatFlags.VerticalCenter);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:39:00+00:00Added an answer on June 16, 2026 at 2:39 am

    Try this:

        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            string[] texts = e.Node.Text.Split();
            using (Font font = new Font(this.Font, FontStyle.Regular))
            {
                using (Brush brush = new SolidBrush(Color.Red))
                {
                    e.Graphics.DrawString(texts[0], font, brush, e.Bounds.Left, e.Bounds.Top);
                }
    
                using (Brush brush = new SolidBrush(Color.Blue))
                {
                    SizeF s = e.Graphics.MeasureString(texts[0], font);
                    e.Graphics.DrawString(texts[1], font, brush, e.Bounds.Left + (int)s.Width, e.Bounds.Top);
                }
            }
        }
    

    You must manage State of node to do appropriated actions.

    UPDATE

    Sorry, my mistake see updated version. There is no necessary to measure space size because it already contains in texts[0].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TreeView where each node has an icon and a descriptive text.
I have a TreeView and I need each node to support multi color text.
I have a TreeView with a parent node and two children node. Each of
Suppose I have a treeview, where each treenode contains an id for a different
I have a form tha contains a TreeView with many Textboxes in each node.
I have a TableView associated to a TreeView. Each time a node in the
I have a treeview which contains, per node, a key and text. However, there
I have a wpf TreeView with customized Items. Each node is a wpf Border
I have an ASP.net TreeView control which displays a hierarchical folder structure. Each node
I have a TreeView setup so that each TreeViewItem has right-click context menu applied

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.