Window overlay

Hi,

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.

Any pointers would be really appreciated.

Thanks

Nathan

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.

just an idea (not been tested)

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. :frowning:

If I add the rectangle at the back how can I attach hundreds of controls so that the parent is the rectangle rather than doing them one at a time?

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 usually control this via state.

  1. Add a new boolean window property (mWindowBusy).
  2. Move your logic which currently sets the control enabled / disabled state into a separate method.
  3. Modify this logic so that it also includes the mWindowBusy property when determining if the control should be enabled or not.
  4. In the required places set / reset mWindowBusy and then call the method which updates the control state.

Try a Canvas?

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

Unfortunately I get the following error when I try the code.

Type "Control" has no member named "enabled" obj.enabled = Self.CtrlStateEnabled(i)

Try replacing

obj.enabled=flag

With

if obj isa RectControl then RectControl(obj).enabled=flag End if

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.