-1

How do I change control properties outside of the main form class?

I have a function that takes a form object as a parameter

public MyFunc(Form f)
{
    // I want to do something like this
    f.lblMylabel.txt = "foo"
}

How do I reference the forms controls and change property values?

Guerrilla
  • 13,375
  • 31
  • 109
  • 210
  • This should work (apart from the obvious syntax errors), Is your label set as private? It would be much better to make a method on your form to do this also – Sayse Aug 26 '15 at 13:16
  • possible duplicate of [Best way to access a control on another form in Windows Forms?](http://stackoverflow.com/questions/8566/best-way-to-access-a-control-on-another-form-in-windows-forms) – adv12 Aug 26 '15 at 13:19
  • If I create control by dragging it onto form in designer, where do I set the accessibility to public? – Guerrilla Aug 26 '15 at 13:51

1 Answers1

0

When you open a form in your mdi parent form, set that form object public and then get it by the reference of mdi parent class.

Lali
  • 2,816
  • 4
  • 30
  • 47