I'm trying to find a way that I can cause my application's main window to appear only if the user has never run the application before. If they've run it before, then there's no need to display the window (this is all in .NET mind you).
So I figured, well, in the Form1 constructor, I can set Visible = false if I don't want to display the window. Nope. So then I thought, maybe it can go in Form1.Load. Nope. Then I thought, maybe the handle needs to be created, so I made an event handler for the HandleCreated event. Nope.
Where, oh where, do you put code to hide the window on launch? This should not be that difficult of an issue (which means I am missing something obvious).
well.. if you want, you could dangerously edit the "Generated Code" section of the form InitializeComponent
on Initialize would be the best bet..
Tried the InitializeComponent code, and no go there. It gets called from the Form1 constructor, so I'm not surprised. I don't know what "Initialize" you're talking about -- I don't see it in the list of events.
jackpot
http://windowsforms.net/articles/notifyiconapplications.aspx
Awesome! That worked out. It's entirely too complicated to make this work -- you'd think they would just honor the .Visible property..
Another thing that pisses me off is the form editor will not let you go into design mode if the form class is not the first class in the namespace. Wtf is up with that?
Here is what I do...I dont know if this is exactly the same in C# or if it is what you are needing, but you might gain something from it...
So you have an application, lets same the NameSpace is "AaronsProgram". Create a Class File, called, "ProgramStarter.cs" and be sure to use System.Windows.Forms at the top. Make sure it is NameSpace AaronsProgram, and then have a Sub Main in there. One Call - Application.Run(FormName.ActiveForm)
Set projet start to call that Main Sub.
In your FormName form, in the generated code, comment out the call to InitializeComponent()...
then in your form code, make a Public Sub New() and the first call should be to InitializeComponent()
it gives you a little more control....in the ProgramStarting class you can add functionality, etc. You just need to make sure that the ProgramStarting Class and your Form Class are in the same Namespace, etc....
if this doesnt make sense, let me know
That's just a slight twist on the link that Jake posted -- I can see how that would work as well. Thanks for the tip!