c# - Load a form without showing it -
short version: want trigger form_load() event without making form visible. doesn't work because show() ignores current value of visible property:
tasksform.visible = false; tasksform.show();
long version: have winforms application 2 forms: main , tasks. main form displayed. user can either click button open tasks form, or click buttons run task directly without opening tasks form.
when user asks run task directly, i'd call public methods on tasks form without showing it. unfortunately, task logic depends on stuff happens in form_load() event. way can find trigger form_load() call show(). best i've been able show form in minimized state:
tasksform.windowstate = formwindowstate.minimized; tasksform.show();
i suppose cleanest solution pull tasks logic out of tasks form , controller class. can use class main form , tasks form, , load tasks form when need visible user. however, if it's easy thing load form without displaying it, smaller change.
i totally agree rich b, need @ placing application logic rather trying cludge winforms mechanisms. of operations , data tasks form exposing should in separate class kind of application controller or held main form , used tasks form read , display data when needed doesn't need form instantiated exist.
it seems pain rework it, you'll improving structure of app , making more maintainable etc.
Comments
Post a Comment