Using different color for different part of text in the tooltip RRS feed

  • Question

  • Hi,

    I have MS chart in windows form.

    In chart's tooltip I want to use different color for each line of text.

    I derived the tooltip class.

    It is always drawing last line.

    public class MyToolTip : ToolTip { public MyToolTip () { this.OwnerDraw = true; this.Draw += new DrawToolTipEventHandler(OnDraw); } public MyToolTip (System.ComponentModel.IContainer Cont) { this.OwnerDraw = true; this.Draw += new DrawToolTipEventHandler(OnDraw); } Color[] colors = { System.Drawing.Color.Red, System.Drawing.Color.Green, System.Drawing.Color.Black }; private void OnDraw(object sender, DrawToolTipEventArgs e) { string s = e.ToolTipText; string[] s1 = s.Split('\n'); int j=0; foreach (string i in s1) { DrawToolTipEventArgs newArgs = new DrawToolTipEventArgs(e.Graphics, e.AssociatedWindow, e.AssociatedControl, e.Bounds, i, this.BackColor, colors[j], e.Font);

    j++; newArgs.DrawBackground(); newArgs.DrawBorder(); newArgs.DrawText(TextFormatFlags.TextBoxControl); } } }

    Please help me to resolve my problem.

    • Edited by sgrm123 Friday, May 24, 2019 6:54 AM
    Friday, May 24, 2019 6:08 AM

All replies