System,console in Windows Forms?

  • Thread starter Thread starter foldface
  • Start date Start date
F

foldface

Hi
(1) Is there any way of getting output from a windows form on the command line?
(2) (less important). I'm making a File Dialog via a windows Form, I don't
actually need the form and immeadiately hide it, can I do without it?

Ta
F
 
* (e-mail address removed) scripsit:
(1) Is there any way of getting output from a windows form on the command line?

(2) (less important). I'm making a File Dialog via a windows Form, I don't
actually need the form and immeadiately hide it, can I do without it?

?!?
 

Thanks but this appears to be making another windows form, I want to run a
executable on the command line, see a Windows Form appear and later I want the
Windows form to disappear and some text to appear on the command line,
e.g.

d:\home > prog.exe
(do some windows stuff)
text from windows program
d:\home > dir (etc)



This is why I want to do it. Basically I have a text program and via

FOR /F %%a in ('myprog $1') Do Set In=%%a

I want to run myprog, have a file dialog appear and have the name of the
file picked with the file dialog appear here.
 
Thanks but this appears to be making another windows form, I want to run a
executable on the command line, see a Windows Form appear and later I want the
Windows form to disappear and some text to appear on the command line,
e.g.

d:\home > prog.exe
(do some windows stuff)
text from windows program
d:\home > dir (etc)

In that case just make it a console project. There's nothing to stop
you from using Windows Forms in console projects - it's just that
there'll always be a console around. Oh, and in VS.NET you'll need to
add references to the relevant assemblies.
 
* (e-mail address removed) scripsit:
Thanks but this appears to be making another windows form, I want to run a
executable on the command line, see a Windows Form appear and later I want the
Windows form to disappear and some text to appear on the command line,
e.g.

d:\home > prog.exe
(do some windows stuff)
text from windows program
d:\home > dir (etc)

Just add a reference to "System.Windows.Forms.dll" and show a form
inside your console application.
 
Just add a reference to "System.Windows.Forms.dll" and show a form
inside your console application.

lovely, this does what I wanted, the bottom method is a bit on the ugly side
though.


using System;
using System.Windows.Forms;

namespace FileDialogConsole
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Application.Run(new Form1());

}
}

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

static bool firstPass = true;
override protected void OnVisibleChanged(System.EventArgs e)
{
base.OnVisibleChanged(e);
if(firstPass == true)
{
firstPass = false;
FolderBrowserDialog dir = new FolderBrowserDialog();
this.Hide();
dir.ShowDialog(this);
System.Console.WriteLine(dir.SelectedPath);
Application.Exit();
}
}

#endregion
}
}
 
lovely, this does what I wanted, the bottom method is a bit on the ugly side
though.

You don't need to create and run a form - just run:

new FolderBrowserDialog().ShowDialog();

and it should be fine.
 
Back
Top