vb.net - Opening a second-form more than once error -


i have button in form1 opens form2. using frm2.show(). works totally fine first time open frm2, when close frm2 , click on button in frm1 open frm2 again, error:

enter image description here

can tell me how solve it?

edit: have module have database connection , declaration forms:

public frmgame new game public frmplay new play public frmfinish new gamefinish public frmlogin new login public frmmanage new manage public frminsert new toevoegen 

where open form when click on button in form1.

sounds me close()ing frm2. closing form should dispose , release resources, can't show() again. instead, need create new instance of object, this:

frm2=new form2() frm2.show() 

if doesn't work (perhaps because don't want re-initialize form's data members), use hide(), rather close() temporarily hide form during program's execution.

if need prevent form being closed x button, can few different methods:

  1. the best way go may hide or disable close button. read on this post better idea of how that.

  2. you can use formclosing event, either inside frm2 or main window. set cancel property on formclosingeventargs object gets passed in. problem here need provide additional code path close form when want close. closereason property of formclosingeventargs object should give way handle properly. needless say, riskiest way things, since need window close when application shuts down, you're intentionally block happening.

  3. you catch formclosed event in the form spawns frm2, create new instance of window. again, you'll need provide code path allow window close when application shuts down.

in all, method 1 safest. can close window .close() when application shuts down, user can't close x button.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -