Multiple Forms Hiding and closing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    Multiple Forms Hiding and closing

    Hi,
    I have an app that requires 4 child forms each created on a separate thread.
    Each form holds a 3rd Party Phone answering control.
    The control will only answer the phone if the form has been displayed.
    Instantiating the form is not enough.
    The only way I have been able to display the form(s) is myForm.ShowDial og();
    myForm.Show() does nothing. (Code snippet below.)
    So...
    I can't issue a hide instruction as the calling code is waiting for the
    dialog to return.
    I thought maybe a hide in the form's constructor but no, that's ignored as
    well.
    Any ideas on how hide these would be appreciated.
    thanks
    Bob
    ***In MAIN FORM'S CTOR****
    ThreadStart ts1 = new ThreadStart(Mak eLine1);

    Thread t1 = new Thread(ts1);

    t1.SetApartment State(Apartment State.STA);

    t1.Start();

    *************** ***********

    private void MakeLine1()

    {

    frmAnswer f1 = new frmAnswer(1);

    f1.ShowDialog() ;

    }


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Multiple Forms Hiding and closing

    Hi,

    "Bob" <bob@nowhere.co mwrote in message
    news:ulLtztD7GH A.1248@TK2MSFTN GP03.phx.gbl...
    Hi,
    I have an app that requires 4 child forms each created on a separate
    thread.
    Not possible, they must be created from the UI thread

    Each form holds a 3rd Party Phone answering control.
    The control will only answer the phone if the form has been displayed.
    Instantiating the form is not enough.
    The only way I have been able to display the form(s) is
    myForm.ShowDial og();
    myForm.Show() does nothing. (Code snippet below.)
    Of course, you have to call Show(), now what if you create the form, set it
    as minimized and set that does not appear in the task bar?

    Did you tried to make your form transparent?

    why dont y ou want to show the forms in the first pkace?



    --
    Ignacio Machin
    machin AT laceupsolutions .com


    Comment

    • Bruce Wood

      #3
      Re: Multiple Forms Hiding and closing


      Bob wrote:
      Hi,
      I have an app that requires 4 child forms each created on a separate thread.
      Each form holds a 3rd Party Phone answering control.
      The control will only answer the phone if the form has been displayed.
      Instantiating the form is not enough.
      The only way I have been able to display the form(s) is myForm.ShowDial og();
      myForm.Show() does nothing. (Code snippet below.)
      So...
      I can't issue a hide instruction as the calling code is waiting for the
      dialog to return.
      I thought maybe a hide in the form's constructor but no, that's ignored as
      well.
      Any ideas on how hide these would be appreciated.
      thanks
      Bob
      ***In MAIN FORM'S CTOR****
      ThreadStart ts1 = new ThreadStart(Mak eLine1);
      >
      Thread t1 = new Thread(ts1);
      >
      t1.SetApartment State(Apartment State.STA);
      >
      t1.Start();
      >
      *************** ***********
      >
      private void MakeLine1()
      >
      {
      >
      frmAnswer f1 = new frmAnswer(1);
      >
      f1.ShowDialog() ;
      >
      }
      As Ignacio pointed out, you can't create / display forms using other
      threads. You can create / display forms only from the UI thread.

      As well, you problem is likely that you created the frmAnswer form, did
      a .Show(), and then your thread continues executing... and terminates,
      so the frmAnswer form is then closed and disposed.

      I believe that a good start toward resolving this problem would be to
      reverse the relationship between the thread and the form: create the
      frmAnswer form, and have that in turn create the background thread. So,
      the form owns the thread, not the other way around.

      Comment

      Working...