开发者

adding a context menu left click event to a notify icon

开发者 https://www.devze.com 2023-02-11 21:53 出处:网络
A notifyIcon is down in task bar, a user left clicks on it, how to show the contex开发者_运维技巧tmenu after left click?

A notifyIcon is down in task bar, a user left clicks on it, how to show the contex开发者_运维技巧tmenu after left click?

Also, How to make it go away with another left lick anywhere else?

Thanks in Advance...!


If your using Visual studio this is very easy, just add a notify icon to the form in the IDE then add a contextmenu item,

in order to see the notify icon it needs to have an icon(.ico) and the context menue needs to be populated with a menue structure .

in the notify icon properties set the ContectMenuStrip property to your context menue i.e Contextmenue1. By default if a user right clicks the icon it will show the menue and will hide it when they click elsewhere,

If you actualy need that to happen with left click then you need to code that

Private Sub NotifyIcon1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click

    ContextMenuStrip1.Show(Control.MousePosition)

End Sub

Geting it to close on left click is a bit different, if your form is still open you can use a click event in the main form

Private Sub Form1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseClick
    If ContextMenuStrip1.Visible = True Then
        ContextMenuStrip1.Visible = False

    End If
End Sub

If not then i would recomend that you tie in to mouse movement instaed of a click, i.e when the mouse leaves the menue it closes

 Private Sub ContextMenuStrip1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuStrip1.MouseLeave
    ContextMenuStrip1.Close()


End Sub

Hope this is what you were looking for

0

精彩评论

暂无评论...
验证码 换一张
取 消