Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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).

Posted
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.
  • Leaders
Posted

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

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...