Console dans une forms

fredspv Messages postés 127 Date d'inscription dimanche 7 mars 2004 Statut Membre Dernière intervention 6 juin 2008 - 15 nov. 2005 à 14:14
tmcuh Messages postés 458 Date d'inscription dimanche 22 décembre 2002 Statut Membre Dernière intervention 18 avril 2009 - 6 mars 2009 à 14:38
Bonjour,


J'aimerais savoir s'il etait possible d'inserer System.Console dans un formulaire ? Si oui, comment ?

Merci

fred

3 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
15 nov. 2005 à 14:41
c'est ca que tu veux ?

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "app.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string result = process.StandardOutput.ReadToEnd();

Sébastien FERRAND
[MVP C#]
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
15 nov. 2005 à 19:41
La méthode de Seb te permet de rediriger la console dans un TextBox par exemple. Tu peux aussi créer et fermer la console comme ça :

class MainForm : Form
{
[ DllImport( "kernel32.dll", SetLastError = true ) ]
private static extern bool AllocConsole( );


[ DllImport( "kernel32.dll", SetLastError = true ) ]
private static extern bool FreeConsole( );

//[ DllImport( "kernel32.dll", SetLastError = true ) ]
//private static extern bool AttachConsole( uint processID );


private MainForm( ) : base( )
{

}


protected override void OnLoad( EventArgs e )
{
//base.OnLoad( e );


if ( AllocConsole( ) )
{
Console.WriteLine( "The console is open." );
}
}


protected override void Dispose( bool disposing )
{
if ( !FreeConsole( ) )
MessageBox.Show( "Unable to free the console." );


base.Dispose( disposing );
}

[ STAThread ]
private static void Main( )
{
Application.Run( new MainForm( ) );
}
}
0
tmcuh Messages postés 458 Date d'inscription dimanche 22 décembre 2002 Statut Membre Dernière intervention 18 avril 2009
6 mars 2009 à 14:38
Quelqu'un a t-il la solution à cette question : comment ne pas fermer l'application quand on quitte la console? J'ai essayé la procédure AttachConsole à un Thread, mais rien n'y fait...

merci
0
Rejoignez-nous