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 ?
Because its an extension method on RichTextBox, it needs to be static, also it needs to be inside a static class.
thiskeyword in method parameters is defining it as an extension method on RichTextBoxFrom MSDN – Extension Methods
From MSDN – this keyword
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:
later you can call it like: