简体   繁体   中英

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!

You don't want to "call a class", you want to "call a method in some class".

That method apparently should change the color of a selection in a richtextbox in your form. The way to do that is to give that editor control as parameter to your method.

something like:

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

and use it from the form like:

private void TextChangedEvent(object sender, EventArgs e)
{
    TE.High.ChangeSelection(rtb); // assuming 'rtb' is your control
}

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM