views:

55

answers:

3

The main problem is as follows: I did my code in console application and I don't know how can I include my code to WinForms application.

I am using Visual studio 2008.

I need to know where I should paste my code. Thanks.

A: 

You can add both projects to a single solution in VS. Then, simply reference your console project from your Winforms project. This way, both your console and your Winforms project can share code.

You could also copy your code to your Winforms project from the console project. You can simply copy and paste within visual stuio, or right click on the project in the Solution Explorer, select Add, then select Existing Item. Navigate to the .vb or .cs file in the selector and pick your old files.

If you're looking for where the "code" is in a winforms application, just double click a blank space on the form. The "code-behind file" will come up. The Form.Loaded event handler is almost equivalent to the main method in your console application.

Sean Turner
+1  A: 

You'll need to provide a lot more information Thaier.

What exactly does you code currently do. For example, if your console application writes out text using, Console.WriteLine(); you'll probably want to change that to write to a textbox or listbox in the GUI version.

Like wise, is there any user input in the console application, or command line arguments (string [] args) being passed to the main method.

If so you'll probably want to change the way this user input is accepted in your WinForms app.

If you just have a snippet that you need to run immediately when the application launches, look at the Form.Loaded event which will execute your code as soon as the application starts.

Eoin Campbell
A: 

Go to project properties and change the output type from Console Application to Windows Application. You'll also want to look at the things Eoin Campbell mentioned, and make sure you have the right startup object selected.

If I'm understanding your question correctly, this should be all you need to do.

John M Gant