0
\$\begingroup\$

In my game I have 2+ forms and 4+ usercontrols. Where should I declare, lets say a textbox that I use in form2, but I need to modify it in form1.

Should I make them public in their own form/usercontrol or should I make a static class with all the controls?

(Edited to clarify my question) I want to know the most used and flexible way.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ From the FAQ: "Would a professional game developer give me a better/different/more specific answer to this question than other programmers?" I don't think so. \$\endgroup\$
    – user744
    Aug 14, 2011 at 15:53
  • \$\begingroup\$ This belongs at stackoverflow. \$\endgroup\$ Aug 14, 2011 at 19:00
  • 1
    \$\begingroup\$ @Joe Wreschnig: but but... a game programmer would optimize for speed, then everything is public members (save function calls), no? :) \$\endgroup\$
    – jv42
    Aug 15, 2011 at 7:28

1 Answer 1

2
\$\begingroup\$

I think I would make the actual TextBox private in its Form, then expose functionality (like get/set text) using either methods or properties, depending on 'obviousness' factor, ie:

public string Text1
{
    get { return myTextBox1.Text; }
    set { myTextBox1.Text = value; }
}

or...

public void SetTextFromVars(int var1, DateTime var2)
{
    myTextBox1.Text = String.Format("Hey, I have got {0} objects since {1}", var1, var2);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .