close a form

G

Guest

Hi all,

How to close(unload) a Windows form on load event and not let to be
displayed when a criteria is met?
Form 1 calls form2 as frmForm2.Show
and in Form2_Load event I'm chekcing for a criteria and if it's true close
form2 and returns to form1.
Me.Close is not working here.
Thanks in advance,

Roy
 
S

Stoitcho Goutsev \(100\)

Roy,

I can't reproduce the problem neither with .NET 1.1 nor .NET 2.0. I have
seen such a question before, though, so I take it there might be a problem.

Can you give some more info:
1. The version of the framework.
2. Is there any exception?
3. How do you handle the Load event inside the second form overriding the
OnLoad method or hooking on the Load?
4. How do you show the form - Show or ShowDialog?

The best would be if you can post some simple compilable code that
demonstrates the problem.
 
H

Herfried K. Wagner [MVP]

Roy said:
How to close(unload) a Windows form on load event and not let to be
displayed when a criteria is met?
Form 1 calls form2 as frmForm2.Show
and in Form2_Load event I'm chekcing for a criteria and if it's true close
form2 and returns to form1.

Instead of checking the criteria in the form's 'Load' event which is called
directly before the form gets shown, check it in the form's constructor and
throw an exception if the criteria is not met.
 
P

pop.nagarro.com

Roy said:
Hi all,

How to close(unload) a Windows form on load event and not let to be
displayed when a criteria is met?
Form 1 calls form2 as frmForm2.Show
and in Form2_Load event I'm chekcing for a criteria and if it's true close
form2 and returns to form1.
Me.Close is not working here.
Thanks in advance,

Roy

Calling this.Close() in the form2_load works fine.

Vivek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top