472,348 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

closing a form before it loads.

In a vb 6 app in the activate event I was able to do some
testing and if something failed, I was able to exit the
form and return to the caller form.

I have tried everything and searched web but can't find
way to do this in vb.net. Some say throw an exception,
but I don't know what exception to throw and how to exit
from the catch to return to the caller form.
thanks for any help
Nov 20 '05 #1
5 1460
When creating a new instance of your form you could call a function which
performs the test from the calling form (calling class) so you would have:

dim fooForm as new SuperForm()
if fooForm.passesTests then
fooForm.show()
else
fooForm.dispose()
end if

Or something like that. Is this what you are asking? Sorry if I missed the
point.

-MC D
"smhaig" <an*******@discussions.microsoft.com> wrote in message
news:5f****************************@phx.gbl...
In a vb 6 app in the activate event I was able to do some
testing and if something failed, I was able to exit the
form and return to the caller form.

I have tried everything and searched web but can't find
way to do this in vb.net. Some say throw an exception,
but I don't know what exception to throw and how to exit
from the catch to return to the caller form.
thanks for any help

Nov 20 '05 #2
Hi I did not go into it, I admit, as it is complicated.
I am actually putting info on all open forms in a list
collection of classes each of which holds info on each
form (such as the handle and the name of the form). In
the activate code I check to see if this form info class
is in the collection (it is put in the list in the
caller form between f = new form2 and f.show). If it is
not, then the form does not load.

Since I do not know anything about what goes on behind
the scenes I cannot say whether your code would work.

Hope that helps.
-----Original Message-----
When creating a new instance of your form you could call a function whichperforms the test from the calling form (calling class) so you would have:
dim fooForm as new SuperForm()
if fooForm.passesTests then
fooForm.show()
else
fooForm.dispose()
end if

Or something like that. Is this what you are asking? Sorry if I missed thepoint.

-MC D


Nov 20 '05 #3
smhaig,

In each form, you can shadow the show method and determine if it should be
shown, or if an already open instance should be activated
The following example assumes you have a singleton collection class
FormCollection that maintains your 'open' forms
Also note that the form needs to be removed from the collection when the
form is closed

Public Class myForm

Private Shadows Sub Show()
'Check an instance of this form is not already open
Dim frm As Form
For each frm in FormCollection.GetInstance
If TypeOf frm is myForm Then
'The document is already open, so dispose this instance
Me.Dispose()
'Activate the original instance
frm.Activate()
'Exit the sub
Exit Sub
End If
Next
'Add the form to the collection
FormCollection.GetInstance.Add(Me)
'Show the form
MyBase.Show()
End Sub

Stephen
"smhaig" <an*******@discussions.microsoft.com> wrote in message
news:30****************************@phx.gbl...
Hi I did not go into it, I admit, as it is complicated.
I am actually putting info on all open forms in a list
collection of classes each of which holds info on each
form (such as the handle and the name of the form). In
the activate code I check to see if this form info class
is in the collection (it is put in the list in the
caller form between f = new form2 and f.show). If it is
not, then the form does not load.

Since I do not know anything about what goes on behind
the scenes I cannot say whether your code would work.

Hope that helps.
-----Original Message-----
When creating a new instance of your form you could call

a function which
performs the test from the calling form (calling class)

so you would have:

dim fooForm as new SuperForm()
if fooForm.passesTests then
fooForm.show()
else
fooForm.dispose()
end if

Or something like that. Is this what you are asking?

Sorry if I missed the
point.

-MC D

Nov 20 '05 #4
I have a few questions on this last post. From where is
this called? From the caller form or the called form
that needs to be checked. I know from testing that I
could not use dispose() in the activate or load event of
the form I want to dispose. So I am not sure where this
goes.The checking of the collection stuff I have in a
module and I return a boolean and from that boolean
decide whether to continue with the load or not. So the
question is where does your code get placed and who calls
it.

The code I am having problems with could be used in many
situations, not just mine. Its really a question of
closing a form before a load for whatever reason.
-----Original Message-----
smhaig,

In each form, you can shadow the show method and determine if it should beshown, or if an already open instance should be activated
The following example assumes you have a singleton collection classFormCollection that maintains your 'open' forms
Also note that the form needs to be removed from the collection when theform is closed

Public Class myForm

Private Shadows Sub Show()
'Check an instance of this form is not already open
Dim frm As Form
For each frm in FormCollection.GetInstance
If TypeOf frm is myForm Then
'The document is already open, so dispose this instance Me.Dispose()
'Activate the original instance
frm.Activate()
'Exit the sub
Exit Sub
End If
Next
'Add the form to the collection
FormCollection.GetInstance.Add(Me)
'Show the form
MyBase.Show()
End Sub

Stephen
"smhaig" <an*******@discussions.microsoft.com> wrote in messagenews:30****************************@phx.gbl...
Hi I did not go into it, I admit, as it is complicated.
I am actually putting info on all open forms in a list
collection of classes each of which holds info on each
form (such as the handle and the name of the form). In the activate code I check to see if this form info class is in the collection (it is put in the list in the
caller form between f = new form2 and f.show). If it is not, then the form does not load.

Since I do not know anything about what goes on behind
the scenes I cannot say whether your code would work.

Hope that helps.
>-----Original Message-----
>When creating a new instance of your form you could
call a function which
>performs the test from the calling form (calling
class) so you would have:
>
>dim fooForm as new SuperForm()
>if fooForm.passesTests then
> fooForm.show()
>else
> fooForm.dispose()
>end if
>
>Or something like that. Is this what you are asking?

Sorry if I missed the
>point.
>
>-MC D

.

Nov 20 '05 #5
* "smhaig" <an*******@discussions.microsoft.com> scripsit:
In a vb 6 app in the activate event I was able to do some
testing and if something failed, I was able to exit the
form and return to the caller form.

I have tried everything and searched web but can't find
way to do this in vb.net. Some say throw an exception,
but I don't know what exception to throw and how to exit
from the catch to return to the caller form.


Better: Don't even instantiate the class. For example, you can add
a public shared method to the class which returns the reference to the form:

\\\
Public Shared Function Create() As MyForm
If ... Then
Return New MyForm()
Else
Return Nothing ' :-).
End If
End Function
///

Usage:

\\\
Dim f As MyForm = MyForm.Create()
If f Is Nothing Then
...
Else
...
End If
///

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? ...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent...
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text...
6
by: Marc R. | last post by:
Hi all, I just use the new found Class : Class JoinTextBoxColumn Inherits DataGridTextBoxColumn Is there a way to lets VS 2002 to know that is...
2
by: Lauren Wilson | last post by:
Hi folks, I believe I have seen this in this group in the past but my search comes up with nothing so far. I want to prevent our Access...
2
by: rdemyan via AccessMonster.com | last post by:
I have a custom message form that I want to display when the user shuts down my app. Some clean up needs to be done during shutdown and I want to...
3
by: Arne Beruldsen | last post by:
The migration from VB6 is anything but easy. Ok...I have an introductory form (start-up is via sub main) and then several succeeding forms which...
0
by: Rinoa | last post by:
I'm developing a program with a login form. I want the login in form to be the first form that loads, and I want it to close itself when the main CP...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.