سؤال

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

نصائح أخرى

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
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top