Results 1 to 6 of 6

Thread: [RESOLVED] How to know when pressing minimize button?

  1. #1

    Thread Starter
    Lively Member jpgonc's Avatar
    Join Date
    May 2005
    Posts
    75

    Resolved [RESOLVED] How to know when pressing minimize button?

    I have a NotifyIcon that, when the main form is minimized, the user clicks in it and the form windowstate returns to normal, but the problem is knowing when the user minimizes the main form window... (The notifyicon is hide while the form is in normal state)

    And how can I set the program running in background?

    Thanks in advance
    ----------------------------------------------------
    Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
    ----------------------------------------------------

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to know when pressing minimize button?

    Use the WindowState property in the Resize event handler:
    VB Code:
    1. Private Sub Form1_Resize(...) Handles MyBase.Resize
    2.     Me.Notifyicon1.Visible = (Me.WindowState = FormWindowState.Minimized)
    3. End Sub
    This will hide and show the NotifyIcon as needed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member jpgonc's Avatar
    Join Date
    May 2005
    Posts
    75

    Re: How to know when pressing minimize button?

    WOW! This was a record reply! Thanks JMC!
    Btw, do you know how to set an app running in background?

    Thanks for the help.
    ----------------------------------------------------
    Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
    ----------------------------------------------------

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to know when pressing minimize button?

    I'm not sure what you mean by running in the background. An application is generally considered to be a foreground process and a service is considered to be a background process. If you want your app to continue processing while it's in the tray without affecting other running applications responsiveness, you could reduce the priority of its main thread:
    VB Code:
    1. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    2.         If Me.WindowState = FormWindowState.Minimized Then
    3.             Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.BelowNormal
    4.             Me.ShowInTaskbar = False
    5.             Me.NotifyIcon1.Visible = True
    6.         Else
    7.             Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.Normal
    8.             Me.ShowInTaskbar = True
    9.             Me.NotifyIcon1.Visible = False
    10.         End If
    11.     End Sub
    This could reduce the responsiveness of your tray icon's menu though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member jpgonc's Avatar
    Join Date
    May 2005
    Posts
    75

    Re: How to know when pressing minimize button?

    Thank you JMC, I knew that and how to implement it, but I didn't express clearely... I was saying that I would like my app (When minimized) didn't showed on the minimized bar next to Start Menu in Windows.
    ----------------------------------------------------
    Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
    ----------------------------------------------------

  6. #6

    Thread Starter
    Lively Member jpgonc's Avatar
    Join Date
    May 2005
    Posts
    75

    Re: How to know when pressing minimize button?

    JMC, I found, nothing more EASY!!
    What I wanted besides the help you gave me was hidding my application in taskbar...

    I had only to do Me.ShowInTaskbar = False....

    Thanks, this has been resolved.
    ----------------------------------------------------
    Centaurs were mythological creatures like chimeras and satyrs and they had a tendency to violence, except Chiron, who taught Greek heroes.
    ----------------------------------------------------

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