I have created a form using multitouch with the Windows7.Multitouch.dll The form contains a Panel and 3 Buttons The buttons each populate the Panel with either 6 Red Pictureboxes with touch enabled or an animated gif
The Problem is when I leave the non touch page for the 2nd time I get an IDE error - CallbackOnCollectedDelegate occured.
I have wrapped all procedures with try catch, but this happens outside of the routines
I have not been able to find the cause of the error or how to trap and handle it
I would appreciate any help
The form consists on 1 Panel and 3 buttons
Here is the code for the form
Thanks
Imports Windows7.Multitouch
Imports MySql.Data.MySqlClient
Imports System.IO
Public Class Form1
Dim sql_connection As New MySqlConnection
Dim str_path As String = "C:\\dev_folder\\"
Dim str_query As String
Dim bol_touch_down(5) As Boolean
Dim ray_touch_handle(5) As TouchHandler
Dim ray_pic(5) As PictureBox
Private WithEvents touch_handle_1 As TouchHandler
Private WithEvents touch_handle_2 As TouchHandler
Private WithEvents touch_handle_3 As TouchHandler
Private WithEvents touch_handle_4 As TouchHandler
Private WithEvents touch_handle_5 As TouchHandler
Private WithEvents touch_handle_6 As TouchHandler
Sub New()
Try
InitializeComponent()
touch_handle_1 = ray_touch_handle(0)
touch_handle_2 = ray_touch_handle(1)
touch_handle_3 = ray_touch_handle(2)
touch_handle_4 = ray_touch_handle(3)
touch_handle_5 = ray_touch_handle(4)
touch_handle_6 = ray_touch_handle(5)
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub write_sql(ByVal str_query As String)
Dim sql_reader As MySqlDataReader = Nothing
Dim sql_command As New MySqlCommand(str_query, sql_connection)
sql_reader = sql_command.ExecuteReader
sql_reader.Close()
End Sub
Sub load_page(page_id As String)
Try
ReDim ray_pic(5)
ReDim ray_touch_handle(5)
pan_main.Controls.Clear()
Dim int_loop As Integer
Select Case page_id
Case "Page 1", "Page 2"
For int_loop = 0 To 5
Dim obj_pic As New PictureBox
With obj_pic
.BorderStyle = BorderStyle.FixedSingle
.BackColor = Color.Red
.Height = pan_main.Height * 0.2
.Width = .Height
.Name = "pic_" & int_loop + 1
Select Case page_id
Case "Page 1"
If int_loop < 3 Then .Left = pan_main.Width * 0.1 Else .Left = pan_main.Width * 0.5
Select Case int_loop
Case 0, 3
.Top = pan_main.Height * 0.05
Case 1, 4
.Top = pan_main.Height * 0.3
Case 2, 5
.Top = pan_main.Height * 0.55
End Select
Case "Page 2"
If int_loop < 3 Then .Top = pan_main.Height * 0.1 Else .Top = pan_main.Height * 0.5
Select Case int_loop
Case 0, 3
.Left = pan_main.Height * 0.05
Case 1, 4
.Left = pan_main.Height * 0.3
Case 2, 5
.Left = pan_main.Height * 0.55
End Select
End Select
pan_main.Controls.Add(obj_pic)
ray_pic(int_loop) = obj_pic
add_touch_events(obj_pic)
End With
Next
Case "Page 3"
Dim obj_new_pic As New PictureBox
With obj_new_pic
.BorderStyle = BorderStyle.FixedSingle
.Height = pan_main.Height * 0.9
.Left = pan_main.Width * 0.05
.Image = System.Drawing.Image.FromFile("D:\Dropbox\Tablet Source\-=Modules=-\app_concar_hmi\app_concar_hmi\bin\Debug\Resources\Instructions\iron man suit case suit.gif")
.SizeMode = PictureBoxSizeMode.Zoom
.Top = pan_main.Height * 0.05
.Width = pan_main.Width * 0.9
End With
pan_main.Controls.Add(obj_new_pic)
End Select
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub change_page(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
Try
load_page(sender.text)
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Function get_touch_array_id(ByRef obj_object As Object, ByRef obj_array As Array)
Dim int_id As Integer = -1
Try
Dim int_loop As Integer
For int_loop = 0 To obj_array.GetUpperBound(0)
If Windows7.Multitouch.TouchHandler.ReferenceEquals(obj_object, obj_array(int_loop)) = True Then
int_id = int_loop
Exit For
End If
Next
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
Return int_id
End Function
Sub add_touch_events(ByRef obj_object As Object)
Try
Dim int_touch_id As Integer
For int_touch_id = 0 To ray_touch_handle.GetUpperBound(0)
If IsNothing(ray_touch_handle(int_touch_id)) Then
ray_touch_handle(int_touch_id) = Win32Helper.Factory.CreateHandler(Of TouchHandler)(obj_object.Handle)
AddHandler ray_touch_handle(int_touch_id).TouchDown, AddressOf touch_handle_down
AddHandler ray_touch_handle(int_touch_id).TouchUp, AddressOf touch_handle_up
Exit For
End If
Next
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub set_touch_colour(ByRef obj_pic As PictureBox, ByVal bol_active As Boolean)
Try
If bol_active = True Then obj_pic.BackColor = Color.GreenYellow Else obj_pic.BackColor = Color.Red
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub touch_handle_down(ByVal sender As Object, e As TouchEventArgs)
Try
Dim int_trigger_id As Integer = get_touch_array_id(sender, ray_touch_handle)
trigger_touch_event(ray_pic(int_trigger_id), int_trigger_id, True)
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub touch_handle_up(ByVal sender As Object, e As TouchEventArgs)
Try
Dim int_trigger_id As Integer = get_touch_array_id(sender, ray_touch_handle)
trigger_touch_event(ray_pic(int_trigger_id), int_trigger_id, False)
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub trigger_touch_event(ByRef obj_pic As PictureBox, ByVal int_array_id As Integer, ByVal bol_enable As Boolean)
Try
bol_touch_down(int_array_id) = bol_enable
set_touch_colour(obj_pic, bol_enable)
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
Sub record_event(ByVal str_type As String, ByVal str_subroutine As String, ByVal str_detail As String)
Try
Dim stream_writer As StreamWriter
Dim str_file As String = str_path & "log\\multitouch_test_" & Format(Now(), "yyMMddHHmmss") & ".log"
If Not File.Exists(str_file) Then File.Create(str_file).Close()
stream_writer = New StreamWriter(str_file, True)
stream_writer.WriteLine(Format(Now(), "dd/MM/yyyy HH:mm:ss ff") & " - " & str_type & " - " & str_subroutine & " - " & str_detail)
stream_writer.Flush()
stream_writer.Close()
Catch ex As Exception
record_event("Error", System.Reflection.MethodBase.GetCurrentMethod.Name, ex.Message)
End Try
End Sub
End Class