It really depends what is happening in the Click event-handler, but to do
what you want /without the form/, you need to (as somebody suggested the
other day) refactor this bit of code out into a separate method, which you
can call either on it's own, or via the UI; example:
**old**
private void btn_Click(object sender, EventArgs e) {
// do lots of things
}
**new**
private void btn_Click(object sender, EventArgs e) {
DoLotsOfThings();
}
internal static void DoLotsOfThings() {
// do lots of things
}
then in your Main() you can call WhateverClass.DoLotsOfThings();
*however*, if your code (aka // do lots of things) is genuinely working with
the form (instance) elements, than you will struggle to move it out without
a lot more work.
Note that the VS2005 IDE can help with most of this just by selecting the
code you want to split out, right-click, refactor, extract method..., give
it a name - job done.
Marc
"lavu" <th******@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
I am trying to start a C# GUI App and automatically trigger a button
click event.
However when I add a statement btn.PerformClick to my Main() I get an
error that a class was expected .
This is what I am trying to do.
static void Main(string[] args)
{
.......
Application.Run(new frmMain());
btnTest.PerformClick();
}
and the error is
MyApp.frmMain.btnTest denotes a 'field' where a 'class' was expected.
I do not want to add the code to frmMain() since GUI comes up only
after the button click has already been executed. Waht would be the
best way to do it ?
Any ideas are appreciated.