.net - There is a property to determine whether a Form (and it's controls) is loaded? -


i clarify know how check if form loaded setting boolean variable flag (ex: dim formisloaded boolean) , setting true after load event of form, restrict usage of [enum].parse method causing exceptio in coden.

but not i'm asking for, not typicall question, please continue reading...


i have eventhandler this:

''' <summary> ''' indicates resulting batch command redirection. ''' </summary> private commandredirection reg2bat.commandredirection =          reg2bat.commandredirection.standard  private sub kryptonradiobutton_commandredirections_checkedchanged(sender object, e eventargs) handles _         kryptonradiobutton_commandredirection_standard.checkedchanged,         kryptonradiobutton_commandredirection_error.checkedchanged,         kryptonradiobutton_commandredirection_all.checkedchanged,         kryptonradiobutton_commandredirection_none.checkedchanged      if cbool(sender.checked)         commandredirection = [enum].parse(gettype(cmd.commandredirection),                                            cstr(sender.tag), true)     end if  end sub 

but if giving me error of type an unhandled exception of type 'system.invalidoperationexception' occurred in program.exe , i'm sure error occurs because form not totally loaded before eventhandler tries acces value of control.

stacktrace:

en system.enum.tryparseenum(type enumtype, string value, boolean ignorecase, enumresult& parseresult)  en system.enum.parse(type enumtype, string value, boolean ignorecase)     en reg2bat.gui.kryptonradiobutton_commandredirection_standard_checkedchanged(object sender, eventargs e)  en c:\users\administrador\desktop\reg2bat\reg2bat\userinterfaces\gui\gui.vb:línea 271   en componentfactory.krypton.toolkit.kryptonradiobutton.set_checked(booleanvalue)  en reg2bat.gui.initializecomponent()  en c:\users\administrador\desktop\reg2bat\reg2bat\userinterfaces\gui\gui.designer.vb:línea 104     en reg2bat.gui..ctor()  en c:\users\administrador\desktop\reg2bat\reg2bat\user interfaces\gui\gui.vb:línea 49 

i improve 'formisloaded?' checking without writting unecessary variables (boolean flags) keep code more pretty , simplified, so, title of question says, i'm asking if exist property, or just, in-one-line solution check whether form loaded in moment.

i'm asking know more improved alternatives setting boolean check form loaded.

by moment i'm trying property (me.isaccessible), , seems working correctlly 'cause [enum].parse method not throws exception, i'm not sure of property checking (i've read intellisense of prop nothing).

private sub kryptonradiobutton_commandredirections_checkedchanged(sender object, e eventargs) handles _         kryptonradiobutton_commandredirection_standard.checkedchanged,         kryptonradiobutton_commandredirection_error.checkedchanged,         kryptonradiobutton_commandredirection_all.checkedchanged,         kryptonradiobutton_commandredirection_none.checkedchanged      if me.isaccessible          if cbool(sender.checked)             commandredirection = [enum].parse(gettype(reg2bat.commandredirection),                                               cstr(sender.tag), true)         end if      end if      msgbox(commandredirection.tostring)  end sub 

so, using me.isaccessible property it's properlly solution check if form/controls loaded? if not, there property check this?.

i believe you're looking form.ishandlecreated confirm is built (and has gone through initialisecomponent() routine in .designer file.)

after worth checking form.isdisposed make sure has not since been destroyed.

this more difficult in multiple threaded applications because unless can execute check on form's owning thread, state change can happen after doing test.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -