I have a window with lots of controls on, some are enabled and some are disabled. What I want to be able to do is when a button is pressed all of the controls become non accessible whilst an event happens and when it is finished the controls become accessible again like before.
I thought a way to do this was to place a transparent rectangle over all of the other controls and set it to be disabled and set the mouse cursor on the mouse enter event to be the wait icon but I then realised that you cant set it to transparent on MAC and I need the solution to work on both MAC and Windows.
I guess in an ideal world it would be good if I could put a semitransparent rectangle over the window whilst it was doing the event but not sure if that is possible.
I did look at the MBS plugin as it has an overlay function but got confused as to how to implement it to stick to the window in case the user moves the window etc.
Put it behind the controls so that it becomes the parent of all the other controls. You can then enable/disable the child controls by enabling/disabling the parent control.
FUNCTION massEnable(flag as boolean)
Dim i, c As Integer
Dim obj As Control
c = Self.ControlCount - 1
For i = 0 To c Step 1
obj = Self.Control(i)
obj.enabled=flag
Next
END FUNCTION
Great idea but some of the controls are enabled and some are disabled so I cant just blanket enable them all after the event and they change due to other events so I couldnt hard code which ones were which.
The other problem is that I change the cursor on some of the controls using mouse enter / exit which is why I thought about putting the rectangle over the controls so that the mouse doesnt change when you go over those controls that have different cursors.
My guess is that you put the rectangle (parent control) at one side, select all controls that you want to be child of that rectangle and move them over the rectangle.
In my app, I have controls that need to enabled/disabled based on whether or not the window is in edit mode. When I go to edit mode, I set a boolean in the window to true. Then, in the keydown or mousedown event of each control, depending on the control, I return the appropriate boolean based on whether or not that control is allowed to be used.
I would use @Dave S 's method, but add a boolean array as a property of the window that you would load with the enabled state of each control right before they are disabled, and then use that same array to set the enabled state when the controls are re-enabled. Something like:
FUNCTION massEnable(flag as boolean)
Dim i, c As Integer
Dim obj As Control
c = Self.ControlCount - 1
For i = 0 To c Step 1
obj = Self.Control(i)
If flag Then
// restore enabled state
obj.enabled = window1.CtrlState(i)
Else
// store enabled state and then disable
window1.CtrlState(i) = obj.enabled
obj.enabled=False
End
Next
END FUNCTION
Dave’s code wasn’t tested, and I did not test it either after I made the changes, so do what Greg says.
You could even modify “obj IsA RectControl” to be more fine-grained with the control type. For example if you only wanted to disable buttons you would use “obj IsA PushButton”.
[quote=440519:@Nathan Wright]I thought a way to do this was to place a transparent rectangle over all of the other controls and set it to be disabled and set the mouse cursor on the mouse enter event to be the wait icon but I then realised that you cant set it to transparent on MAC and I need the solution to work on both MAC and Windows.
I guess in an ideal world it would be good if I could put a semitransparent rectangle over the window whilst it was doing the event but not sure if that is possible.[/quote]
From what I understand, you want to use a rectangle to group a bunch of controls so you can deactivate all of them at some point and by enabling the rectangle all the controls go back to the enable/disable value they were previously?
I did this test with Canvas, on Mac and Windows, don’t know if that is what you want:
Sample window with some controls
Drag the Canvas over the controls to group, send it to back and move the controls to make the Canvas the parent
Then I put this code to Action event PushButton1:
Canvas1.Enabled = not Canvas1.Enabled
and works the same when remote debugging on Windows 10.
Don’t know if this is what you want. Hope this helps.