Form.ShowDialog is abnormal after Application.Run

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

    Form.ShowDialog is abnormal after Application.Run

    [STAThread]
    Main
    {
    Application.Run (new Form1());
    new Form2().ShowDia log();
    }

    Form2 can't be show. WhatZ the throuble? it seems no messageloop
  • Frans Bouma [C# MVP]

    #2
    Re: Form.ShowDialog is abnormal after Application.Run

    凯仔 wrote:
    [color=blue]
    > [STAThread]
    > Main
    > {
    > Application.Run (new Form1());
    > new Form2().ShowDia log();
    > }
    >
    > Form2 can't be show. WhatZ the throuble? it seems no messageloop[/color]

    The lines above start Form1 as the main form. There's just 1 thread
    (STAThread), as most gui's just use 1 thread, so application.run ,
    starts the form and passes the execution to that form, which then is
    the executing code on the single thread of the application. If you also
    want to show form2, open it from form1.

    Frans

    --
    ------------------------------------------------------------------------
    Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
    LLBLGen Pro website: http://www.llblgen.com
    My .NET blog: http://weblogs.asp.net/fbouma
    Microsoft MVP (C#)
    ------------------------------------------------------------------------

    Comment

    • 凯仔

      #3
      Re: Form.ShowDialog is abnormal after Application.Run

      But why the following code is right ?
      new Form2().ShowDia log();
      Application.Run (new Form1());


      "Frans Bouma [C# MVP]" wrote:
      [color=blue]
      > 凯仔 wrote:
      >[color=green]
      > > [STAThread]
      > > Main
      > > {
      > > Application.Run (new Form1());
      > > new Form2().ShowDia log();
      > > }
      > >
      > > Form2 can't be show. WhatZ the throuble? it seems no messageloop[/color]
      >
      > The lines above start Form1 as the main form. There's just 1 thread
      > (STAThread), as most gui's just use 1 thread, so application.run ,
      > starts the form and passes the execution to that form, which then is
      > the executing code on the single thread of the application. If you also
      > want to show form2, open it from form1.
      >
      > Frans
      >
      > --
      > ------------------------------------------------------------------------
      > Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
      > LLBLGen Pro website: http://www.llblgen.com
      > My .NET blog: http://weblogs.asp.net/fbouma
      > Microsoft MVP (C#)
      > ------------------------------------------------------------------------
      >[/color]

      Comment

      Working...