adress of a handler

DerStauner

Erfahrenes Mitglied
Ich versuche, ein global key class hinzukriegen für meine Anwendung. Dies habe ich im Internet gefunden:

Code:
Public Class Hotkey
		Inherits System.Windows.Forms.Form
		Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, _
		ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As _
		Integer
		Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As _
		IntPtr, ByVal id As Integer) As Integer
		Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" _
		(ByVal lpString As String) As Short
		Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As _
		Short) As Short
		Public Class MODKeys
			Public Const MOD_ALT As Integer = 1
			Public Const MOD_CONTROL As Integer = 2
			Public Const MOD_SHIFT As Integer = 4
			Public Const MOD_WIN As Integer = 8
		End Class
		Dim hotkeyID As Short
		Public Sub New(ByVal sKey As System.Windows.Forms.Keys,Optional ByVal _
		Modulate As Long = 0)
			RegisterGlobalHotKey(sKey,Modulate)
		End Sub
		Private Sub RegisterGlobalHotKey(ByVal hotkey As System.Windows.Forms.Keys, _
		ByVal modifiers As Integer)
			Try
				Dim atomName As String = _
				AppDomain.GetCurrentThreadId.ToString("X8") & Me.Name
				hotkeyID = GlobalAddAtom(atomName)
				RegisterHotKey(Me.Handle, hotkeyID, modifiers, CInt(hotkey))
			Catch ex As Exception
				UnregisterGlobalHotKey()
			End Try
		End Sub
		Private Sub UnregisterGlobalHotKey()
			If Me.hotkeyID <> 0 Then
				UnregisterHotKey(Me.Handle, hotkeyID)
				GlobalDeleteAtom(hotkeyID)
				hotkeyID = 0
			End If
		End Sub
		Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
			MyBase.WndProc(m)
			Const WM_HOTKEY As Integer = &H312
			If m.Msg = WM_HOTKEY Then
				RaiseEvent Hit
			End If
		End Sub
		Public Event Hit
	End Class

Und dazu die Verwendung:

Code:
Private Sub DieFunktion()
    Dim HotKeyElement As New Hotkey(System.Windows.Forms.Keys.F12,2) ' 2 = STRG
    AddHandler HotKeyElement.Hit, AddressOf Eventauslöser
End Sub
 
Private Sub Eventauslöser()
    ' Hier kommt alles rein
End Sub

So, ich nehme an, DieFunktion kann z. B. das Load Ereignis eines Forms sein, damit STRG+F12 ein globalet Hotkey wird. Und im Eventauslöser kommt, was das Programm machen muss, wenn man STRG+F12 drückt. Und ich möchte, dass wenn man diese Tastenkombination drückt, dann das Checkbox1.Click Event ausgeführt wird. Aber das krieg ich nicht hin, ich bekomme die Fehlermeldung:

Fehler 1 Der AddressOf-Operand muss dem Namen einer Methode entsprechen (ohne Klammern).


Und wenn ich Checkbox1_Click benutze, dann:

Fehler 1 Die Signatur der Private Sub CheckBox1_Click(sender As Object, e As System.EventArgs)-Methode ist mit dem Delegaten "Delegate Sub HitEventHandler()" nicht kompatibel.


Wo liegt das Problem
 

Neue Beiträge

Zurück