Load a form without showing it

前端 未结 8 1073
梦谈多话
梦谈多话 2020-12-09 19:39

Short version: I want to trigger the Form_Load() event without making the form visible. This doesn\'t work because Show() ignores the current value of the Visible property:<

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 20:31

    Sometimes this would be useful without it being bad design. Sometimes it could be the start of a migration from native to managed.

    If you were migrating a c++ app to .NET for example, you may simply make yourwhole app a child window of the .NET form or panel, and gradually migrate over to the .NET by getting rid of your c++ app menu, status bar, toolbar and mapping teh .NEt ones to your app using platform invoke etc...

    Your C++ app may take a while to load, but the .NET form doesn't..in which you may like to hide the .NEt form until your c++ app has initialised itself.

    I'd set opacity=0 and visible=false to false after calling show, then when your c++ app loads, then reverse.

提交回复
热议问题