Hi all,
here is another solution how to create and handle controls dynamically.
I overloaded the CommandButton class. This allowed me do overload the "mouseClicke()" method and route all incoming events to my central handler.
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Option Explicit
'
' this Class overloads CommandButton to define a special event handler
'
Public ownerForm As frmDynControl ' allows call back to common event handler
Public row As Integer ' we remember row/col to handle events parameterized
Public col As Integer
' a parameterized constructor
Public Sub clsMyDynButton(frm As frmDynControl, c As Integer, r As Integer )
ownerForm = frm
col = c
row = r
End Sub
' Jabaco was not able to find class "MouseEvent"
' before I explicitly selected this class in the Project/Classpath rt.jar tree
Public Sub mouseClicked(e As MouseEvent)
ownerForm.dynButtonClickHandler(Me, e)
End Sub
|
The central event handler in my form:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
|
' "MouseEvent" was not visible in my Jabaco IDE before I explicitly
' selected it in the Project/Classpath rt.jar tree
Public Sub dynButtonClickHandler(btn As clsMyDynButton, e As MouseEvent)
' common click event handler for all clsMyDynButton controls
If Not e.isConsumed Then
' we react just once
msgbox "col=" & btn.col & " row=" & btn.row & vbcrlf & e.toString
' here we might do something clever depending on the btn.Caption
e.consume
End If
End Sub
|
I wonder why I had to "convince" the event handler to execute the events just once. Without checking and setting the "consume" flag, the event handler is executed twice.
Regards
A1880