I have a segmented control that creates container controls in a page panel. It works perfectly. However, there is a design flaw: when you press on the same segmented control item multiple times in a row, the page panel creates multiple instances of the container control.
[quote=73979:@Shane Gibbs]I have a segmented control that creates container controls in a page panel. It works perfectly. However, there is a design flaw: when you press on the same segmented control item multiple times in a row, the page panel creates multiple instances of the container control.
How would I prevent this? Thanks,
Shane.[/quote]
Normally you would iterate through all of the controls on the window, checking for the specific ContainerControl (using Isa) but a ContainerControl isn’t actually a real Control, despite the name.
The simplest way is to just create a boolean property with a False default for each ContainerControl that you want to create. When the CC is created, just flip the boolean for that CC to True.
In the SegmentedControl’s Action event, try something like this:
Select Case itemIndex
Case 0
If aExists Then
Beep
System.DebugLog "ContainerControl already exists"
Return
Else
Dim a As New contA
a.EmbedWithin(Self, 0, 0)
aExists = True
End If
Case 1
// Creates a contB, changes the bExists property to True etc
End Select
A ContainerControl in a window’s control loop appears as a EmbeddedWindowControl:
For i As Integer = 0 To ControlCount - 1
If Control(i) IsA EmbeddedWindowControl Then
// now we know it is a ContainerControl
End
Next
Unfortunately there is neither a way to cast the EmbeddedWindowControl to a ContainerControl nor is there a property “ContainerControl” in the class EmbeddedWindowControl. But you can check the Handle property:
For i As Integer = 0 To ControlCount - 1
If Control(i) IsA EmbeddedWindowControl Then
Dim ewc As EmbeddedWindowControl = EmbeddedWindowControl(Control(i))
Select Case ewc.Handle
Case ContainerControl_1.Handle
...
Case ContainerControl_2.Handle
...
End
End
Next