Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I'm trying to halt startup of an application in the application events. If I put e.cancel in the startup event, that does the trick but only sort of. The main form still flashes into view for a few milliseconds. How can I stop it from starting entirely? The need for this has to do with licensing. If it's not a valid license, I'm showing a licensing form and then I want to cancel the rest of startup. Don't want anything else to occur. I have an OnInitialize event where I'm doing some other startup things but I can't figure out how to halt startup in there.

Thanks.
Posted

Sounds like you have the main form as the startup up form.

Options;
1) Use another form e.g. a Licensing form as the startup form and only if the licensing is satisfied load the main form
2) Start the application using a Sub Main
3) Set the main forms default visibility to hidden

Personally i would rewrite the startup and licensing check to perform this in a standalone form, this way if the license is invalid it shows an appropriate message to the user to give them an idea of the issue.
 
Share this answer
 
Handle the Form Load event, and if the validation fails use Close:
VB
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If (Not IsValid()) Then
        Close()
    End If
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900