Nice and easy solution is using the following concept :
Code:
Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
   'check the close reason why form is closing 
If e.CloseReason <> CloseReason.WindowsShutDown Then
' if windows is NOT shutting down then
'code what to do if user clicks X goes here
'example:
If MsgBox("Do you want
...