Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Creating controls on a form that is programmatically created on another form in Visual Studio

I have an assignment to create a windows form with a button that opens another form that takes user input and converts feet to meters (among other things).

I know how to create the original form AND open the child form. What I don't know and can't find a clear answer about is HOW to put controls on the second form.

I am not looking for someone to do my homework for me but I would like a clear description of what I do to put buttons on that child form. I am pretty sure I can write the conversion code itself.

Am I making a form in visual studio that is CALLED by the parent form, or am I writing the code onto the parent form that gives the child its own controls that can be take the user input?

I hope I asked that clearly. Thanks very much.

Nancy Melucci

2 Answers

Steven Parker
Steven Parker
231,236 Points

Are you required to create the button dynamically from server code? Or can you open the new form in design view and drag the button from the controls palette onto the form? (that's the easy way!)

I wouldn't expect in either case that you would do any of this from the first form. And wouldn't the second one be a "peer" to the first and not a "child"?

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Ah, I am still new to this and a little ignorant. I always think of the thing that is created first as the parent. The first thing that is created is a form that gives the user a choice to open a second form (and there are two options - english to metric OR metric to english.) I have to create code that allows one of those two options to be called.

I'll try the latter thing you suggested, and let you know how it goes, thanks!