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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NotifyIcon App

Status
Not open for further replies.

kadara

Programmer
Mar 2, 2012
26
0
0
DE
Hi,

I created the following NotifyIcon App:

Code:
'
' Created by SharpDevelop.
' User: kadara
' Date: 14.06.2013
' Time: 11:09
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System.Threading

Public NotInheritable Class NotificationIcon
	Private notifyIcon As NotifyIcon
	Private notificationMenu As ContextMenu

	#Region "Initialize icon and menu"
	Public Sub New()
		notifyIcon = New NotifyIcon()
		notificationMenu = New ContextMenu(InitializeMenu())

		AddHandler notifyIcon.DoubleClick, AddressOf IconDoubleClick
		Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(NotificationIcon))
		notifyIcon.Icon = DirectCast(resources.GetObject("$this.Icon"), Icon)
		notifyIcon.ContextMenu = notificationMenu
	End Sub

	Private Function InitializeMenu() As MenuItem()
		Dim menu As MenuItem() = New MenuItem() {New MenuItem("About", AddressOf menuAboutClick), New MenuItem("Exit", AddressOf menuExitClick)}
		Return menu
	End Function
	#End Region

	#Region "Main - Program entry point"
	''' <summary>Program entry point.</summary>
	''' <param name="args">Command Line Arguments</param>
	<STAThread> _
	Public Shared Sub Main(args As String())
		Application.EnableVisualStyles()
		Application.SetCompatibleTextRenderingDefault(False)

		Dim isFirstInstance As Boolean
		' Please use a unique name for the mutex to prevent conflicts with other programs
		Using mtx As New Mutex(True, "Notify01", isFirstInstance)
			If isFirstInstance Then
				Dim notificationIcon As New NotificationIcon()
				notificationIcon.notifyIcon.Visible = True
				Application.Run()
				notificationIcon.notifyIcon.Dispose()
				' The application is already running
				' TODO: Display message box or change focus to existing application instance
			Else
			End If
		End Using
		' releases the Mutex
	End Sub
	#End Region

	#Region "Event Handlers"
	Private Sub menuAboutClick(sender As Object, e As EventArgs)
		MessageBox.Show("About This Application")
	End Sub

	Private Sub menuExitClick(sender As Object, e As EventArgs)
		Application.[Exit]()
	End Sub

	Private Sub IconDoubleClick(sender As Object, e As EventArgs)
		MessageBox.Show("The icon was double clicked")
	End Sub
	#End Region
End Class


I would like to add a KeyDown Event (to capture the F12 key). If you have any kind of idea, please show me, I would be greatful.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top