David Brewer
David Brewer

Reputation: 1974

Accessing labels and combo boxes from another form C#

I'm being asked to access labels, text boxes, and combo boxes from another form. From the input form to the main form using this:

frmInput input = new frmInput();

This ^^ is in my main form. When i go to use "intelesense" it doesn't show any of the labels or anything that i need. Suggestions?

Upvotes: 0

Views: 386

Answers (2)

Oleg Rudckivsky
Oleg Rudckivsky

Reputation: 930

That controls can be declared private or protected and that's why you can't access them. However you can either make them public or access by name:

input.Controls["someButtonName"]

Upvotes: 1

S M Kamran
S M Kamran

Reputation: 4503

Because by default GUI elements are defined with private access. If you want to expose them then define your own properties for these elements. You also needs to pass the reference to your main form to the input form... However not recommended.

Instead you can use Events to communicate data between form and keep the rendering to the control's parent form.

Upvotes: 4

Related Questions