yaniv Posted August 6, 2003 Posted August 6, 2003 I want to put a checking and to close the form if some condition is false. I tried to use "me.close" in the formload sub but it make some thing weird, the program is "thinking" the form is open. How can you cancel the form load event. Quote
*Experts* Volte Posted August 6, 2003 *Experts* Posted August 6, 2003 You can do something like this: 1) Create a class, called something like AppInit. 2) Inside it, put code like this:Public Shared Sub Main If myCondition Then Dim f As New Form1() Application.Run(f) End If End Sub 3) Set the project's startup object to Sub Main (from Project Properties). Quote
JABE Posted August 6, 2003 Posted August 6, 2003 Me.Close() from Load event worked for me. What made you observe that the program is "thinking" the form is open? Quote
yaniv Posted August 6, 2003 Author Posted August 6, 2003 because one of main cheking in this app. is to keep the user from opening two forms. and even after the me.close the program doesn't opening the new one. this is the reason i can't use the "main" sub, because i have a lot of form to open or not to open. Quote
Leaders dynamic_sysop Posted August 6, 2003 Leaders Posted August 6, 2003 can you not do this.... ( it works for me ) .... Private myCondition As Boolean '/// boolean is just an example here. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not myCondition Then '/// your stuff here , eg: if something equals a value or not. Me.Dispose() End If End Sub Quote
Winston Posted August 7, 2003 Posted August 7, 2003 You can do something like this: 1) Create a class, called something like AppInit. 2) Inside it, put code like this:Public Shared Sub Main If myCondition Then Dim f As New Form1() Application.Run(f) End If End Sub 3) Set the project's startup object to Sub Main (from Project Properties). i like VolteFace example more, it's really the neat method of implementation, as you can in future thoguhts, do multiple instance checks, instantiate all your forms in this Sub Main routine, it's really handy, and also you can handle Global Exception easily, all in one. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.