Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Chriso on October 19, 2007, 03:45 AM

Title: C# Invoking a Form?
Post by: Chriso on October 19, 2007, 03:45 AM
I am having some problems trying to show a form from another thread, the form gets shown but is in a frozen (non-responsive) state.

Heres the code...

frmProfile p = new frmProfile();
p.Show();


Any ideas?
Title: Re: C# Invoking a Form?
Post by: MyndFyre on October 19, 2007, 04:04 AM
I typically use this delegate for my invocations:

private delegate void SyncDel();


Do you have an instance of your main form?

SyncDel del = delegate()
{
    frmProfile p = new frmProfile();
    p.Show();
};
if (mainForm.InvokeRequired)
    mainForm.Invoke(del);
else
    del();


This should work on any pre-existing control.  You just need a control that's already there.  I'm guessing that you're inside of an event handler - your sender parameter should even work, cast to Control. :)
Title: Re: C# Invoking a Form?
Post by: Chriso on October 19, 2007, 04:36 AM
Thanks a lot mate, its work now :)