Results 1 to 13 of 13

Thread: How do I get the "x" on the form to minimize the form instead of close it?

  1. #1

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901

    How do I get the "x" on the form to minimize the form instead of close it?

    This would be very useful to know.
    Any suggestion?
    SeaHag

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.  
    3. Cancel = -1
    4. Form1.WindowState = vbMinimized
    5.  
    6. End Sub
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Cool thanks..
    Could you tell me how that works?
    Why -1?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    -1 is True in VB so it tells the Form Unload to Cancel itself.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    Sorry guys, won't trapping & re-directing the Unload event of the form prevent it from unloading Ever Ever Ever ??

    Pee

    Best Bar.....

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you can still end the program usind end and set form1 = nothing elsewhere
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    I have a menu system.. seems to exit (end) alright

  8. #8
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    I'm not causing problems here honest...

    but wot if you did'nt want to End the Prog ? Just unload the Form ?? I suppose it can stay Minimised allright, not much overhead...

    Best Bar.....

  9. #9

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    I have the program in the task bar.
    so I dont want people to Exit.

    minimized property forces the program to the taskbar

  10. #10
    Hyperactive Member FATBOYPEE's Avatar
    Join Date
    May 2001
    Location
    Charleville (Ireland) Still. ANYONE GOT A JOB I CAN HAVE ? GIZA JOB. I CAN DO THAT....
    Posts
    463
    Ah yeah, Ok, I was just thinking out-loud really, in a different situation, trapping the Last event of the form could potentially cause infinite looping unless you Ended. Sorry for the annoyance.

    Pee

    Best Bar.....

  11. #11

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Np!!
    I like ideas!

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You should use the QueryUnload event instead of the Unload event.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     If UnloadMode = vbFormControlMenu Then
    3.         Cancel = True
    4.         Me.WindowState = vbMinimized
    5.     End If
    6. End Sub
    This will allow the form to be unloaded using the Unload FormName statement and also allowing Windows to terminate the application if someone closes Windows without first closing the application.

  13. #13

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Ok. Makes sense..

    Thanks! all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width