Get custom canvas control to follow enabled state of GroupBox

  1. last week

    Mark F

    Feb 11 Pre-Release Testers, Xojo Pro Sydney, Australia

    Hi, I have a custom control based on a canvas. When I place this control in a GroupBox, is there a way I can get it to automatically follow the enabled state of the GroupBox like say a CheckBox does?

    Thanks in advance,

    Mark

    Inside your Canvas.Paint put

    If Me.Parent <> Nil And Me.Parent.Enabled = False Then
      system.DebugLog("disabled paint")
    
      g.ForeColor = Color.DarkGray
      g.FillRect(0, 0, g.Width, g.Height)
    Else  
      system.DebugLog("enabled paint")
    
      g.ForeColor = Color.Black
      g.FillRect(0, 0, g.Width, g.Height)
    End If

    I hope that paint gets called on macos/linux as it does on windows when the parent is enabled/disabled, aka. tested working in windows ;)

    Edit: Altered things so it works inside/outside of a container and defaults to enabled if not in one.

  2. Julian S

    Feb 11 Pre-Release Testers, Xojo Pro Answer UK
    Edited last week

    Inside your Canvas.Paint put

    If Me.Parent <> Nil And Me.Parent.Enabled = False Then
      system.DebugLog("disabled paint")
    
      g.ForeColor = Color.DarkGray
      g.FillRect(0, 0, g.Width, g.Height)
    Else  
      system.DebugLog("enabled paint")
    
      g.ForeColor = Color.Black
      g.FillRect(0, 0, g.Width, g.Height)
    End If

    I hope that paint gets called on macos/linux as it does on windows when the parent is enabled/disabled, aka. tested working in windows ;)

    Edit: Altered things so it works inside/outside of a container and defaults to enabled if not in one.

  3. Mark F

    Feb 11 Pre-Release Testers, Xojo Pro Sydney, Australia

    Thanks Julian. Works on macOS and Win10.

or Sign Up to reply!