Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NotifyIcon - Left / Right Click Only 1

Status
Not open for further replies.

BomberMan2K

Programmer
Sep 19, 2007
36
IL
Hi,
I'm trying to make my application to act differently on left or right click on it's tray icon.
I'm using the Click Event - I want my form to show/hide when I left click it, and show a context menu when I right click it. For now - It all happens at the same time.

Is there a solution for this?

Thank you and a good day,
Roman.
 
Hi Roman,

Would the MouseDown event serve you better? The event args for this event allow you to determine which button was pressed.

Hope this helps,

Graeme


"Just beacuse you're paranoid, don't mean they're not after you
 
Perfect, thank you :)

How didn't I think about this?! :)))
 
For the context menu: You simply set the ContextMenuStrip property of the NotifyIcon to the menu. When right clicking the icon, the menu will be shown.

For the showing/hiding: Create a MouseClick (not Click) event, and check the Button property in the MouseEventArgs:

Code:
private void notifyIcon_MouseClick( object sender, MouseEventArgs e )
{
    if ( e.Button == MouseButtons.Left )
    {
        // show/hide form            
    }
}

Hope that helps.

|| ABC
 
Thanks ABC - It really helped a lot.

I Switched to this method, it looks more "right" than mousedown I think.
(though not sure why)

Roman
 
MouseDown occurs when the button is pressed (it won't matter if it is depressed elsewhere and not on the icon)
MouseClick occurs when the button is pressed and depressed on the icon. Hence why it would be more suitable :)

|| ABC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top