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# Projects and Solutions

Can C# programs written for console be adapted for windows form programs?

Hello, I am trying to understand how the code written for a console application can be adapted for a windows form application. I am currently taking a class in C# at my university but my professor is not very thorough and I am looking for other ways to understand C#. My assignments are for windows form applications and I am wondering how the code for a console application can be adapted for windows forms? Any help would be appreciated!

1 Answer

Steven Parker
Steven Parker
231,248 Points

I've done this kind of thing before with C++ programs. It basically involves writing a new UI component, but you can re-use the core functionality code.

Forgive my ignorance in this, since I am new to the coding world. Do you mean you essentially have to write the code for the elements in the form around the logic. Like a nested loop for example; if I write the code for the loop to do something in console, would I just have to write the elements that provide the end user control around it?

Steven Parker
Steven Parker
231,248 Points

A console might use prompts and get input from the user before performing some task. A converted version might display a form with fields to fill in and a "submit" button. The fields and button are the "UI component" I was talking about. But when the button is pressed, the program would do the same thing it did before after the responses to the prompts had been read. That part of the code should be essentially the same.