1

I'm quite new in C# but, I want to make myself a debug console in form dbg. And I want to color and bold the variables that are coming for it, I made an function to easy write to console:

    private void writtodbg(string x, string y)
    {
        string a = Convert.ToString(x);
        string b = Convert.ToString(y);

        Debug.rTB1.AppendText(a, Color.Orange); // bold
        Debug.rTB1.AppendText(" = "); // bold
        Debug.rTB1.AppendText(b + Environment.NewLine, Color.Orange); // bold

    }

But then error occurs which says "No overload for method 'AppendText' takes 2 arguments".

Oxmaster
  • 11
  • 3
  • Why do you think that you can pass two arguments to AppendText? And why have to decided, out of all the available options, to pass a Color-type variable? Why don't you start understanding how to use the given control (even before start using AppendText) rather than trying pointless combinations? – varocarbas Oct 27 '13 at 18:16
  • http://stackoverflow.com/questions/1683779/simple-text-color-in-rich-text-box?rq=1 and http://stackoverflow.com/questions/7923919/how-to-make-some-text-bold-in-a-rich-text-box-c-sharp?rq=1 – Sriram Sakthivel Oct 27 '13 at 18:16

1 Answers1

3

That's because AppendText() can only receive a String. You can't specify the Color. If you're seeing code from somewhere online that has syntax like that then it is probably a custom RichTextBox class where someone has added that ability.

Try something like this:

    private void writtodbg(string x, string y)
    {
        AppendText(x, Color.Orange, true);
        AppendText(" = ", Color.Black, false);
        AppendText(y + Environment.NewLine, Color.Orange, true);
    }

    private void AppendText(string text, Color color, bool bold)
    {
        Debug.rTB1.SelectionStart = Debug.rTB1.TextLength;
        Debug.rTB1.SelectionColor = color;
        Debug.rTB1.SelectionFont = new Font(Debug.rTB1.Font, bold ? FontStyle.Bold : FontStyle.Regular);
        Debug.rTB1.SelectedText = text;
    }
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40