0

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!

Community
  • 1
  • 1

2 Answers2

1

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
}
Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
  • sir how to call it when the RichTextBox was assigned in mainform error in class (rtb) heres the code: public class DtexteditoR : Form { RichTextBox rtb = null; public Dedit() { } –  Mar 01 '13 at 11:11
  • i mean the richtextbox was not assigned from toolbox but in form class itself? how to call it in class –  Mar 01 '13 at 11:14
1

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);
}
Chukwuemeka
  • 342
  • 6
  • 11
  • sir how to call if the richtextbox was not assigned from toolbox but in form class itself? how to call it in class –  Mar 01 '13 at 11:14