Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to GUI from another class

I've GUI with several Labels, Listboxes, NumericUpDown etc. I want read their values in another class. Standard properties of controls are private. How should I do this?

like image 833
Saint Avatar asked Dec 28 '22 16:12

Saint


1 Answers

I believe the most appropriate way to do it would be to encapsulate these GUI elements into properties and expose their data via a getter. e.g.

public string SomeLabelValue
{
   get { return label1.Text;}
}

This protects your element to only being read, while exposing the least amount of data from your object.

You can however expose the entire element and/or allow a setter method to change the values of the element if applicable.

like image 176
George Johnston Avatar answered Dec 31 '22 13:12

George Johnston