B4J Question Supress events if gui is set within programm code

Discussion in 'B4J Questions' started by specci48, Apr 6, 2015.

  1. specci48

    specci48 Well-Known Member Licensed User

    Is it possible to differentiate between user clicked events and events which are fired because of program based setting?

    E.g. there is a Checkbox with
    Code:
    Sub Checkbox_CheckedChange(Checked As Boolean)
      
    ' ... some code
    End Sub
    If the user checks the Checkbox with the mouse, the CheckedChange event and the sub Checkbox_CheckedChange is called.

    If I set
    Code:
    Checkbox.Checked = True
    within my program, the sub Checkbox_CheckedChange ist called, too.

    Is there a way to differ between both calls or better prevent the sub Checkbox_CheckedChange to be called if set within program code?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Check this example:
    Code:
    Sub Process_Globals
       
    Private fx As JFX
       
    Private MainForm As Form
       
    Private chk1 As CheckBox
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
       MainForm.Show
       chk1.Initialize(
    "chk1")
       MainForm.RootPane.AddNode(chk1, 
    1010,5050)
    End Sub

    Sub MainForm_MouseClicked (EventData As MouseEvent)
       SetCheckState(chk1, 
    Not(chk1.Checked))
    End Sub

    Sub SetCheckState(chk As CheckBox, state As Boolean)
       
    If IsNumber(chk.Tag) = False Then chk.Tag = 0
       chk.Tag = chk.Tag + 
    1
       
    If chk.Checked <> state Then chk.Checked = state
    End Sub

    Sub chk1_CheckedChange(Checked As Boolean)
       
    If IsNumber(chk1.Tag) AND chk1.Tag > 0 Then
         chk1.Tag = chk1.Tag - 
    1
         
    Return
       
    End If
       
    Log("User changed state: " & Checked)
    End Sub
    Click on the form to change the value programmatically.
     
  3. specci48

    specci48 Well-Known Member Licensed User

    Thank you, that pointed me into the right direction!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice