Newbie: how do I run change controls on winform from Main method?

M

mortb

Hi,
I want to be able to run a winform from the command line both with and
without arguments

When I create the winform visualstudio I get a main method looking like
this:

STAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}

If I get some commandline parameters I want to run another method
"shrinkPictures"
and I want this second method to manipulate a progressbar on the From so
I've tried:


[STAThread]
static void Main(string[] args)
{
Form1 frm = new Form1();
frm.shrinkPictures(args);
Application.Run(frm);
}

public void shrinkPictures(string [] bitmapFileNames)
{
// do stuff
}

This works, but doesn't show the form until after the method
"shrinkpictures" is finnished
and shifting places on the lines like:

Application.Run(frm);
frm.shrinkPictures(args);

Will not run the method "shrinkPictures" until the user closes the
applicaiton.

How do I solve this?

cheers,
mortb
 
M

Morten Wennevik

Hi mortb

[STAThread]
static void Main(string[] args)
{
Appliction.Run(new Form1(args));
}

Change your Form1 constructor or add another to use the arguments

public Form1(string[] myArgs)
{
}
 
H

Herfried K. Wagner [MVP]

* "mortb said:
STAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}

If I get some commandline parameters I want to run another method
"shrinkPictures"
and I want this second method to manipulate a progressbar on the From so
I've tried:


[STAThread]
static void Main(string[] args)
{
Form1 frm = new Form1();
frm.shrinkPictures(args);
Application.Run(frm);
}

public void shrinkPictures(string [] bitmapFileNames)
{
// do stuff
}

This works, but doesn't show the form until after the method
"shrinkpictures" is finnished
and shifting places on the lines like:

Application.Run(frm);
frm.shrinkPictures(args);

Will not run the method "shrinkPictures" until the user closes the
applicaiton.

How do I solve this?

\\\
frm.Show()
frm.ShrinkPictures(...)
Application.Run()
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top