Hello,
I have a windows form which I am trying to open from another application. While running the utility, the form is opening and closing immediately. I have tried to debug but didnt get any clue. Please help me in solving the problem.
Thanks in advance.
My code looks like this....
public WinForm()
{
//Set the Language property....
oCurrentLangSet = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Globalization.CultureInfo oCurrentCultInfo = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = oCurrentCultInfo;
InitializeComponent();
}
}
public static void Main(string[] args)
{
if (sampleForm == null)
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new WinForm());
sampleForm = new WinForm();
sampleForm .Show();
//sampleForm .ShowDialog();
MBox.Show("Form", NXMessageBox.DialogType.Information, "form loaded");
}
catch (Exception ex)
{
}
}
else
{
try
{
if (sampleForm .WindowState == FormWindowState.Minimized)
sampleForm .WindowState = FormWindowState.Normal;
}
catch (Exception ex)
{
{
if (sampleForm == null)
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new WinForm());
sampleForm = new WinForm();
sampleForm .Show();
//sampleForm .ShowDialog();
MBox.Show("Form", NXMessageBox.DialogType.Information, "form loaded");
}
catch (Exception ex)
{
}
}
else
{
try
{
if (sampleForm .WindowState == FormWindowState.Minimized)
sampleForm .WindowState = FormWindowState.Normal;
}
catch (Exception ex)
{
}
}
}

VulpesPosted Jan 13, 2015, 9:36 AM
This is what the Application.Run(form) method does in a 'standard' Windows Forms application. It then makes the form visible and when that form is closed the message loop is ended and execution returns to the statement after Application.Run(form) in the Main method.
So, try it like this: