Search code examples
c#icsharpcode

C# Class Color to into Form?


related topics:

https://stackoverflow.com/questions/15150797/how-to-separate-condition-codes-from-mainform-to-class-c-sharp https://stackoverflow.com/questions/15132363/color-code-from-class-to-form-condition

how to call class of this color syntax:

namespace TE
{
    class High
    {
            rtb.SelectionColor = Color.Black;
            rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);
    }
}

into inside a void condition in form:

  private void TextChangedEvent(object sender, EventArgs e)
    {
}

really need help so badly .thanks a lot!


Solution

  • You should have the color-changing code in a method like this:

     namespace TE
    {
        public class High
        {
            public static void ChangeMyColor(RichTextBox rtb)
            {
    
                rtb.SelectionColor = Color.Black;
                rtb.SelectionFont = new Font("Courier New", 10, FontStyle.Regular);
            }
        }
    }
    

    Call it like this:

    private void TextChangedEvent(object sender, EventArgs e)
    {
        TE.High.ChangeMyColor(rtb);
    }