Beginner
Location: Sesto Fiorentino, Florence (ITALY)
Occupation: design & development (HW, SW & FW)
Hi Henning,
I hope for a lot that also in Jabaco is possible to manage the arrays of controls as in VB6. I propose a temporary solution, is not very elegant (for nothing!) but...
... we can try!
Best Regards,
maXim
P.S. I apologize for my bad English.
I hope for a lot that also in Jabaco is possible to manage the arrays of controls as in VB6. I propose a temporary solution, is not very elegant (for nothing!) but...
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
..... Public Sub Command1_Click() CommandEx 1 End Sub Public Sub Command2_Click() CommandEx 2 End Sub Public Sub Command3_Click() CommandEx 3 End Sub ..... Sub CommandEx(Index As Integer) MsgBox "the button " & CStr(Index) & " has been pressed!" Select Case Index Case 1 ..... Case 2 ..... Case 3 ..... End Select End Sub |
... we can try!
Best Regards,
maXim
P.S. I apologize for my bad English.
Another Jabaco solution that should solve your problem:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
Dim WithEvents myStateList As VBControlExtender(Me) Dim myStateItems() As PictureBox Public Sub Form_Load() Dim tmpStateItem As PictureBox Const maxX As Integer = 15 Const maxY As Integer = 10 Const offsetX As Integer = 10 Const offsetY As Integer = 10 Const itemWidth As Integer = 23 Const itemHeight As Integer = 10 Dim x As Integer, y As Integer, v As Integer ReDim myStateItems((maxX + 1) * (maxY + 1)) For x = 0 To maxX For y = 0 To maxY v = v + 1 tmpStateItem = New PictureBox() myStateItems(v) = tmpStateItem Call myStateList.AddControl("test" + x + "|" + y, tmpStateItem, x * itemWidth + offsetX, y * itemHeight + offsetY, itemWidth, itemHeight, True) Next Next v = 0 For x = 0 To maxX For y = 0 To maxY v = v + 1 myStateItems(v).BackColor = IIF(Rnd > 0.5, vbRed, vbGreen) Next Next End Sub Public Sub myStateList_Click(ControlID As String) MsgBox ControlID + " pressed!" End Sub |
Dynamic array of controls with class overloading
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.
The central event handler in my form:
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
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
This post has been edited 1 times, last edit by "A1880" (Feb 15th 2009, 11:00pm)
Similar threads
-
Suggestions »-
Control arrays and multiple handling
(Jan 14th 2009, 9:19am)
-
History & News »-
RELEASE: Jabaco 1.4.0 BETA - 2008-11-18
(Nov 21st 2008, 8:52pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
Picture STRETCH
(Dec 24th 2008, 3:58pm)
-
General topics, questions and discussions »-
Split
(Dec 17th 2008, 3:33pm)
