Form: calling Close() method in Load event.

Q

Qwert

Hello,

I try to call the Close( ) method in the Load event of a Form, but it
doesn't seem to work. Any idea why not? And how do I close a Form in it's
own Load event?

Private Sub frmForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Throw New Exception("Close me please.")
Catch
Me.Close()
End Try
End Sub

Thank you.
 
G

Guest

Qwert,

Your code seems to work for me. Does your form load instead of closing? Are
you getting any error messages?

Kerry
 
H

Herfried K. Wagner [MVP]

Qwert said:
I try to call the Close( ) method in the Load event of a Form, but it
doesn't seem to work. Any idea why not? And how do I close a Form in it's
own Load event?

Your code works fine for me on .NET 1.1 SP1. What version of .NET are you
using and how are you showing your form?
 
Q

Qwert

No error messages. When I call Me.Close() in the Load event, the form
doesn't close. Everything contineous like I didn't call Me.Close().
 
Q

Qwert

I have both 1.0 and 1.1 installed, VS.NET(2002, v7.0) says it's using 1.0.

I show the form with the .ShowDialog() method.
 
G

Guest

Qwert,

I just tried your code in VS.Net 2002 and it did not work. When I tried it
in VS.Net 2003 it worked fine.

The Try - Catch block worked in Form_Load, but not the Me.Close()

Kerry Moorman


Qwert said:
I have both 1.0 and 1.1 installed, VS.NET(2002, v7.0) says it's using 1.0.

I show the form with the .ShowDialog() method.
 
Q

Qwert

Hmm and one more m. Weird.

Then I have to do it another way. More work.

Thank y'all for the answers and the testing.

Qwert,

I just tried your code in VS.Net 2002 and it did not work. When I tried it
in VS.Net 2003 it worked fine.

The Try - Catch block worked in Form_Load, but not the Me.Close()

Kerry Moorman
 

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