Load a form without showing it

前端 未结 8 1084
梦谈多话
梦谈多话 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:42

    From MSDN:

    Form.Load
    Occurs before a form is displayed for the first time.

    Meaning the only thing that would cause the form to load, is when it is displayed.
    Form.Show(); and Form.Visible = true; are the exact same thing. Basically, behind the scenes, Show checks for various conditions, then sets Visible to true. So obviously, setting visible to false (which it already is) before showing the form is meaningless.

    But let's forget the technicalities. I completely agree with Rich B and Shaun Austin - the logic shouldn't be in that form anyway.

提交回复
热议问题