kawark
New member
I'm having trouble figuring out how to access my system tray context menu from a winforms opened up from one of the menu choices. The task notifier was created using a module and an applicationcontext so I could start the application without a form.
Here is m simplified code.
When I start my form, in this case fSettings, I can't figure out how to get access back to my context menu. I'd like to modify it based on events that happen on the open form (fSettings).
Any ideas or help would be appreciated.
Thanks.
Here is m simplified code.
VB.NET:
Module Module1
Public OpenFormsHash As New Hashtable
Public Sub Main()
Application.Run(New MyContext)
End Sub
End Module
Public Class MyContext
Inherits ApplicationContext
Private m_Icon1 As Icon
Private WithEvents TrayIcon As New NotifyIcon
'Context Menu/items for the Notification Area Icon
Private WithEvents CMS As New ContextMenuStrip
Private WithEvents mnuExit As New ToolStripMenuItem("Exit")
Private WithEvents mnuManageSettings As New ToolStripMenuItem("Manage Settings")
Private WithEvents mnuManagePermissions As New ToolStripMenuItem("Manage User Permissions")
Private WithEvents mnuInfo As New ToolStripMenuItem("Help")
Private WithEvents Seperator1 As New ToolStripSeparator()
Private WithEvents Seperator2 As New ToolStripSeparator()
Private Event OpenFormHandler(ByVal tab As String)
Public Sub New()
AddHandler OpenFormHandler, AddressOf ShowSettingsForm
TrayIcon.Icon = m_Icon1
TrayIcon.Text = "blah blah blah..."
TrayIcon.Visible = True
'Create the Context Menu
CMS.Items.Add(mnuManageSettings)
CMS.Items.Add(mnuManagePermissions)
CMS.Items.Add(Seperator1)
CMS.Items.Add(mnuInfo)
CMS.Items.Add(Seperator2)
CMS.Items.Add(mnuExit)
CMS.Name = "cmsMain"
TrayIcon.ContextMenuStrip = CMS
My.User.InitializeWithWindowsUser()
CurrentUser = My.User.Name.Replace("ADPCE\", "")
End Sub
Private Sub OnManageSettings(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuManageSettings.Click
ShowSettingsForm("Settings")
End Sub
Private Sub OnManageUserPermissions(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuManagePermissions.Click
ShowSettingsForm("Permissions")
End Sub
Private Sub MyContext_ThreadExit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ThreadExit
TrayIcon.Visible = False
End Sub
#End Region
Private Sub ShowSettingsForm(ByVal tab As String)
Dim fSettings As frmSettings
If OpenFormsHash.Contains("frmSettings") Then
fSettings = OpenFormsHash.Item("frmSettings")
fSettings.BringToFront()
Else
fSettings = New frmSettings
'fSettings.TopMost = True
fSettings.InitialTabToDisplay = tab
fSettings.Show()
End If
End Sub
End Class
When I start my form, in this case fSettings, I can't figure out how to get access back to my context menu. I'd like to modify it based on events that happen on the open form (fSettings).
Any ideas or help would be appreciated.
Thanks.