I'm thinking you need to look at the Project Properties. On the Application tab (for most versions of Visual Studio) you should see some options like Assembly Name, Root namespace, Application Type, Icon, etc. There is also a property for Shutdown mode. If it's set to "When Startup form closes" then any time you close the Startup form (which is also a property set on this page) the entire application will end. You may want to change that to "When last form closes." This way as long as you have a form open (could still be hidden, though) and haven't called Application.Exit(), your app will continue to run.
You also asked about telling the difference between closing a form with a button or using the x. I typically do that by having a class level boolean. It's set to False in the Load event. If I have a button that closes the form I make sure to set the variable to True before closing...like this:
Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHome.Click
boolCloseByButton = True
Home.Show()
Me.Close()
End Sub
Then in my Form Closing I check that variable. If it's set to True I know it's closing because of a button I coded. If it's set to false I know that the user must have hit the X to close the form. If I don't really want the form to close I can use the e.Cancel inside the FormClosing event. For example, here is some code that I use to prompt users, only when they close by using the X, to make sure they want to close the form:
Private Sub Form1(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If Not boolCloseByButton Then
If MessageBox.Show("Do you want to exit?", gblstrFormText, MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End If
End Sub
If the user selects no, the
e.Cancel = True
will stop the form from closing.
Hope this helps.