Results 1 to 9 of 9

Thread: [RESOLVED] Click on NotifyIcon, bring my program to front

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Resolved [RESOLVED] Click on NotifyIcon, bring my program to front

    Hello,

    I have a Notify Icon on the main form of my application. It periodically checks for Alerts (as we call them) and notifies the user if they have new Alerts (very similar to Outlook telling you that you have a new e-mail). When the user clicks on the Notify Icon, it brings the Alerts module to the front if an instance of it is open, and opens a new instance if there is not one.

    But, I would also like for my program to come to the front as if the user clicked on it in the taskbar.

    Does this require some sort of API call?
    I have tried these:
    Me.WindowState = FormWindowState.Normal
    Me.Focus()
    Me.BringToFront()

    but none have worked.

    Any ideas?
    Thanks
    Last edited by 18experience; Mar 29th, 2007 at 08:16 AM.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: Click on NotifyIcon, bring my program to front

    You may want to concider using the BringWindowToTop API function
    VB.NET MVP 2008 - Present

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Click on NotifyIcon, bring my program to front

    Thanks for the idea, I bet this is the right track.

    I put this at the top of my class:
    Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As IntPtr

    and then I call this:
    BringWindowToTop(Me.Handle)

    but nothing is happening. I have used APIs very little. Am I missing something important here?
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Click on NotifyIcon, bring my program to front

    This works for me
    Code:
    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            Me.ShowInTaskbar = True
            Me.NotifyIcon1.Visible = False
        End Sub

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Click on NotifyIcon, bring my program to front

    Excuse me, its a balloon click. So, I'm not looking to do the standard Maximize Form/Make Notify Icon Invisible thing. The program is in the taskbar, and the notify icon is always visible. A balloon pops up if the user gets a new alert, and when they click it I want my application to pop up front. This is what happens when I run this (see attached pic):
    Me.WindowState = FormWindowState.Normal
    BringWindowToTop(Me.Handle)

    This happens when I position Windows Explorer over the form to where I can still see this top and then click the balloon. Notice how it appears selected, but it is still behind Windows Explorer. Is this because I am running it in the debugger?
    Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Click on NotifyIcon, bring my program to front

    I guess this should really be moved to the API forum now. Moderators? Anyone? I would appreciate it.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Click on NotifyIcon, bring my program to front

    Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: Click on NotifyIcon, bring my program to front

    This not an API question. Just call the form's Activate method. If you tried those methods and they didn't work then you should have read their MSDN help topics to see if you were using them incorrectly. If you'd done that for the Focus method then you'd have seen this:
    Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
    If we as developers cannot read help documentation then there is no hope for our users.
    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Click on NotifyIcon, bring my program to front

    RobDog888, thanks for the move.

    jmcilhinney - sorry, I know how much you talk about the MSDN help topics. And I agree with what you say about reading help documentation. Thanks for the help, that worked perfectly, by the way.

    Thanks again, everyone.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

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