Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello Smile | :)
 
For testing purposes I created a C# ConsoleLine application. Now I want to do a GUI and so I choose Project --> Add component and added a "Windows Forms" element. But although there is no Console.WriteLine or something left he always opens the Console and he does not show my Windows Forms Element. What am I to do that the Console disappears and the Windows Forms Element appears?
 
Thank you a lot for helping me in my newbie question Smile | :)
 
Best regards,
Florian
Posted 10-Mar-13 6:54am
Flo_89266
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

By keeping the same project, you can change the output type:
 
1. Go to the properties of your project (right click on the project in VS).
2. In the context menu, choose properties.
3. In the window that appears, Select the Application tab (Should be the first one by default).
4. Change the Output Type for Windows Application. Save the changes.
5. In the Main function of the file Program.cs put this code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;    // This import is needed.

namespace MyTest
{
    class Program
    {
 
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main()); // Main here is the name of my form.
                                         // Put the name of YOUR form or Constructor
                                         // if it is not the same.
            
        }
 
    }
}
 
And In the Form :
 
 
    // This is the constructor of your form.
    public Main()
    {
        InitializeComponent();
        Load += new EventHandler(Main_Load);  // Optional. Just an on Load event.
    }
 
    // The is the event on Form load. it is optional.
    private void Main_Load(object sender, EventArgs e)
    {
        listener.start();
    }
 
I hope this will help!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

find main method wich is first method to start debug !
write this line :
 System.Windows.Forms.Application.Run(new Form1()); // i consider Form1 is your windows form class
this line will make your windows form and will show it !
do not forget to add System.Windows.Forms to your project references!
and this is a typically Main method wich VisualStudio will make for a windows form application!
[STAThread]
 static void Main()
  {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
  }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

In your Program.cs
You Must Run the GUI on another Thread :
 
Just add For Exemple:
 
 
Console.Write("Running the GUI...\nPress Enter To Abort"); 
 
new System.Threading.Thread(()=>{System.Windows.Forms.Application.Run(new  Form1());}).Start();
 
Console.ReadLine();
System.Windows.Forms.Application.Exit();
 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100