I'm working on a scientific/algebraic calculator and I have put all of the code that will deal with any of the math in a separate class. However I cannot access any of the controls on the form from this class. I need to write the answer into the box on my form called AnswerBox. How do I allow this other class to use controls on the form?
WildBamaBoy
19
Junior Poster
Recommended Answers
Jump to PostIn your form add a property like so:
public decimal Answer { get { return Convert.ToDecimal(AnswerBox.Text); } set { AnswerBox.Text = value.ToString(); } }
Then in your other class add a reference to the form and set the Answer property accordingly.
class Calculator { …
Jump to PostCan you pass the text box as a parameter to your Start method?
public static void Start(string e, TextBox answerBox) { Entry = e; //Determine what to do to the entry. In this case 2 + 2 // ... // update the text box with the answer …
All 5 Replies
darkagn
315
Veteran Poster
Featured Poster
WildBamaBoy
19
Junior Poster
darkagn
315
Veteran Poster
Featured Poster
WildBamaBoy
19
Junior Poster
darkagn
315
Veteran Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.