Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:53:11+00:00 2026-06-10T17:53:11+00:00

public void AppendText(this RichTextBox box, string text, Color color) { box.SelectionStart = box.TextLength; box.SelectionLength

  • 0
public void AppendText(this RichTextBox box, string text, Color color)
{
    box.SelectionStart = box.TextLength;
    box.SelectionLength = 0;

    box.SelectionColor = color;
    box.AppendText(text);
    box.SelectionColor = box.ForeColor;
} 

It was public static void

But then i had an error on this line in my Form1:

public partial class Form1 : Form

The error is on the Form1 say:

Error Extension method must be defined in a non-generic static class

If i remove the static from the function im getting error on the AppendText say:

Error Extension method must be static

How do i work with that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:53:12+00:00Added an answer on June 10, 2026 at 5:53 pm

    Because its an extension method on RichTextBox, it needs to be static, also it needs to be inside a static class.

    this keyword in method parameters is defining it as an extension method on RichTextBox

    AppendText(this RichTextBox box.......
    

    From MSDN – Extension Methods

    Extension methods are defined as static methods but are called by
    using instance method syntax.Their first parameter specifies which type the method operates on, and the parameter is preceded by the this modifier.

    From MSDN – this keyword

    The this keyword refers to the current instance of the class and is
    also used as a modifier of the first parameter of an extension
    method.

    if you want to create an extension method on RichTextBox, then you can have to define this method as static and also have it in a static non-generic class something like:

    public static class MyExtensions
    {
       public static void AppendText(this RichTextBox box, string text, Color color)
       {
        box.SelectionStart = box.TextLength;
        box.SelectionLength = 0;
    
        box.SelectionColor = color;
        box.AppendText(text);
        box.SelectionColor = box.ForeColor;
       } 
    }
    

    later you can call it like:

    RichTextBox yourRichTextBox = new RichTextBox();
    yourRichTextBox.AppendText("Some Text",Color.Blue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void log(String msg, Color c = Color.black) { loggerText.ForeColor = c; loggerText.AppendText(\n +
public static void WriteLine(string text) { StreamWriter log; if (!File.Exists(Filename)) { log = new
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
using richtextbox control programatically i'm appending text to the richtextbox . richTextBox1.AppendText(hello); somehow the
public void actionPerformed(ActionEvent e) { String sout; try { if(e.getSource()==compile) { sout=input.getText(); Runtime rt=Runtime.getRuntime();
public void printList( ){ Node<E> p ; System.out.printf( [ ) ; for ( p=head.next
public void swap(Point var1, Point var2) { var1.x = 100; var1.y = 100; Point
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Init(); backthread tr=new backthread(); tr.execute(0,0,0); } backthread
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map); TextView lattv=(TextView)findViewById(R.id.lat); TextView lngtv=(TextView)findViewById(R.id.lng); JSONParstring jParser =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.