473,573 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1532
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.passesT ests 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*******@disc ussions.microso ft.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.passesT ests 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*******@disc ussions.microso ft.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.passesT ests 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 classFormCollecti on 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*******@disc ussions.microso ft.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.passesT ests 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*******@disc ussions.microso ft.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
5806
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 MDI parent window which subsequently closes the MDI child window. My application does certain logic when the user actually closes the MDI child form by clicking the "X" in the upper right hand. ...
1
2196
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? Thank
10
4002
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 remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms,...
2
3006
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 box. However, if one enters invalid data in then and then attempts to close the window (either via my custom 'Close' box or by clicking the close 'X' in the upper right window corner), the...
6
1321
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 more then DataGridTextBoxColumn add DataGridBoolColumn. I would like to add this one in the available list "Add"
2
2428
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 application from closing without some kind of confirmation from the user. We already have a tiny hidden form that loads from a function called by the autoexec macro. I KNOW it is loading because I...
2
2554
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 display this form and then display various messages in the label on the form as the shutdown cleanup proceeds. I have a hidden Startup form. So in the Startup form OnClose event, I am loading...
3
1655
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 gather some info. As soon as the info is gathered they can be closed for good, Based on the info...I refer to a module which loads another form and possibly several others. In VB6 as soon as all...
0
1158
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 loads. However, when I set frmLogIn as the startup form and attempt to close it upon loading the next form it closes the entire program. Private Sub btnLogin_Click(ByVal sender As System.Object,...
0
7705
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7796
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5601
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2224
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.