I made a custom button to input keypresses:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class KeyInputButton
Inherits System.Windows.Forms.Button
'UserControl1 overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
' Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
End Sub
End Class
Public Class KeyInputButton
Public Event KeyCombinationChanged(ByVal sender As System.Object, ByVal kc As TestControls.KeyCombination)
Private _KeyCombination As TestControls.KeyCombination = Nothing
Public Property KeyCombination() As TestControls.KeyCombination
Get
Return _KeyCombination
End Get
Set(ByVal kc As TestControls.KeyCombination)
_KeyCombination = kc
Text = _KeyCombination.toString
End Set
End Property
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub Me_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
KeyCombination = New TestControls.KeyCombination(e.Control, e.Alt, e.Shift, e.KeyValue)
RaiseEvent KeyCombinationChanged(Me, KeyCombination)
End Sub
End Class
When I put a KeyInputButton in a Form and start the debugger, I get the following exception (I get the same exception in VS2005 and VS2010):
"System.InvalidOperationException was unhandled
Message="Er is een fout opgetreden bij het maken van het formulier. Zie ExceptionInnerException voor details. De fout is: De objectverwijzing is niet op een exemplaar van een object ingesteld."
Source="WindowsApplication1"
StackTrace:
bij WindowsApplication1.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 190
bij WindowsApplication1.My.MyProject.MyForms.get_Form1()
bij WindowsApplication1.My.MyApplication.OnCreateMainForm() in C:\Documents and Settings\Tetra\Mijn documenten\Visual Studio 2005\Projects\TestControls\WindowsApplication1\My Project\Application.Designer.vb:regel 35
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
bij WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()
I have no idea how to fix this, I tried rebuilding everything. Hopefully someone can help me with this.
EDIT: KeyCombination class:
Public Class KeyCombination
Public Control As Boolean
Public Alt As Boolean
Public Shift As Boolean
Public Value As Integer
Private Const MOD_ALT = 1
Private Const MOD_CONTROL = 2
Private Const MOD_SHIFT = 4
Public ReadOnly Property modifiers() As Integer
Get
If Not control And Not alt And shift Then
Return MOD_SHIFT
End If
If Not control And alt And Not shift Then
Return MOD_ALT
End If
If Not control And alt And shift Then
Return MOD_ALT Or MOD_SHIFT
End If
If control And Not alt And Not shift Then
Return MOD_CONTROL
End If
If control And Not alt And shift Then
Return MOD_CONTROL Or MOD_SHIFT
End If
If control And alt And Not shift Then
Return MOD_CONTROL Or MOD_ALT
End If
If control And alt And shift Then
Return MOD_CONTROL Or MOD_ALT Or MOD_SHIFT
End If
End Get
End Property
Public Sub New(ByVal c As Boolean, ByVal a As Boolean, ByVal s As Boolean, ByVal v As Integer)
Shift = s
Control = c
Alt = a
Value = v
End Sub
Public Overrides Function toString() As String
Dim Ret = ""
If control Then
ret += "Control + "
End If
If alt Then
ret += "Alt + "
End If
If shift Then
ret += "Shift + "
End If
Return Ret & System.Windows.Forms.Keys.GetName(GetType(System.Windows.Forms.Keys), Value)
End Function
End Class