Sorry if this is a simple question, I'm newish to c#. To simplify this, I have one form (this is in WinForms), let's say Form1 that has a textbox (A rich textbox that allows multiple lines). During runtime I need to be able to access that textbox and get everything the user has written and put that into a string. I can do that just fine (within the form), the problem I run into is getting that text from another class. Right now I have it set up so I have this method, within the form:
public int getWords()
{
int goals = 15;
string words = mainTextbox.Text;
int count = words.Split(' ').Length;
MessageBox.Show(count.ToString());
return count;
}
I tried to call the method from my class, let's call it Words, but the textbox text always came up as empty. It took me (a little too long) to realize that by creating a new instance of the form, I was basically resetting the textbox and that's why it came up as empty even though it wasn't.
I've looked through dozens of other questions like my own on StackOverflow but none of them really worked for me, nor did they explain how they worked. So my question is: How can I get the text from a textbox in Form1, to Class Words, during runtime. The simplest way possible, and the most dumbed-down explanation as possible, please and thank you!