|
-
Dec 14th, 2006, 03:15 PM
#1
[RESOLVED] Question about Sub Main()
I have an application that I am writing and i was initially using a form as the startup, but I want to use sub Main() as the start. This is the sub
VB Code:
Sub main()
Application.EnableVisualStyles()
Application.DoEvents()
'Check to see if an installer is flagged for deletion
Dim inFile As String = My.Settings.KillInstaller
'if updates are enabled then do a check
If My.Settings.enableUpdates = True Then
'if flagged, delete the recent installer
If inFile <> String.Empty Then
'check to see if installer exists in the temp directory
If IO.File.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & "\" & inFile) Then
'Delete the previous installer
IO.File.Delete(My.Computer.FileSystem.SpecialDirectories.Temp & "\" & inFile)
'Update my.settings flag
My.Settings.KillInstaller = String.Empty
End If
End If
'Check for any new updates and run the update form if any exist
If checkUpdates() Then Exit Sub
End If
'Run the login screen
Application.Run(New Login)
Application.Exit()
End Sub
It does a few things that are irrelevant to my question, which is this. I have enableVisualStyles in the sub, however when the application is run from this method, as opposed to haveing a form as startup item, all the linkLabels in my application look horrible, almost like it is changing the font. Has anyone else seen anything like this or perhaps see any errors in my code?
Thanks
-
Dec 14th, 2006, 04:02 PM
#2
Re: Question about Sub Main()
I can tell you are using 2005 from your use of the My keyword.
So if you are using a Sub Main to start, that means you have disabled the application framework correct?
-
Dec 14th, 2006, 04:16 PM
#3
Re: Question about Sub Main()
-
Dec 14th, 2006, 04:21 PM
#4
Re: Question about Sub Main()
well is there a specific reason you need to use a sub main. A better way (I guess maybe you could say the 2005 way) would be to leave the application framework enabled and don't use Sub Main
So I guess you wanted to use sub main so that the first code to run when your app starts does not have to be a form, right?
Go into your project properties, and select the first tab (application).
click the "View Application Events" button and you will get a code screen where some events can be coded for that are global to your app (like when the app is opened, or closed, etc...)
so you can write code in the MyApplication_Startup event instead of a submain.
it even has event args like commandline params, or cancel, if you wanted to cancel the app from proceeding further (ie don't display your first form because a condition was not met)
this would likely be the best solution, and would also not cause you to need to use application.enablevisualstyles, which has been buggy since it was introduced.
-
Dec 14th, 2006, 04:23 PM
#5
Re: Question about Sub Main()
Thank you much, I originally was using a form as the initial item and still could but I didn't think that using sub Main would be such a headache. Thanks for the good info... rate up ^^
-
Dec 14th, 2006, 04:25 PM
#6
Re: [RESOLVED] Question about Sub Main()
Glad to help.
I discovered all this when moving a 2003 app to 2005. The 2003 app had a sub main, and I didnt want to give it up, but I also wanted to gain the functionality of the application framework. That lead me to the application events.
Because if you disable the application framework you lose some cool features that can make coding a bit easier at times
-
Dec 14th, 2006, 08:20 PM
#7
Re: [RESOLVED] Question about Sub Main()
Hey I have a question about the application events. When I open that, it is just completely blank. I don't see where you were talking about the MyApplication_Startup event, do I need to create these?
EDIT: Nevermind seems to just be in that project... wonder how i pooched that one haha oh well I will deal with it tomorrow
-
Dec 15th, 2006, 10:16 AM
#8
Re: [RESOLVED] Question about Sub Main()
it might have been caused from you turning off and back on the application framework
if you need it, here is the IDE created code which is in ApplicationEvents.vb
VB Code:
Namespace My
' The following events are availble for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
End Class
End Namespace
from there you select MyApplication Events from the left drop down at the top of the code view, and then you can select the events to program for from the right drop down (like like normal)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|