GUI enabling/disabling of controls: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 751: Line 751:
End
End
</lang>
</lang>

=={{header|Gambas}}==
<lang gambas>hValueBox As ValueBox 'We need a ValueBox
hButton0 As Button 'We need a button
hButton1 As Button 'We need another button

Public Sub Form_Open()

With Me 'Set the Form's Properties..
.height = 95 'Set the Height
.Width = 350 'Set the Width
.Arrangement = Arrange.Vertical 'Arrange items vertically
.Padding = 5 'Border area
.Title = "GUI enable/disable" 'Title displayed on the Form
End With

hValueBox = New ValueBox(Me) As "ValBox" 'Add a ValueBox to the Form as Event 'ValBox'

With hValueBox 'Set the ValueBox's Properties..
.Expand = True 'Expand the ValueBox
.Value = 0 'Set it's value to 0
End With

hButton0 = New Button(Me) As "ButtonInc" 'Add a Button to the form as Event "ButtonInc"

With hButton0 'Set the Button's Properties..
.Height = 28 'Set the Height
.Text = "&Increment" 'Add Text (The '&' adds a keyboard shortcut)
End With

hButton1 = New Button(Me) As "ButtonDec" 'Add a Button to the form as Event "ButtonDec"

With hButton1 'Set the Button's Properties..
.Height = 28 'Set the Height
.Text = "&Decrement" 'Add Text (The '&' adds a keyboard shortcut)
.Enabled = False 'Disable the button
End With

End

Public Sub ButtonInc_Click() 'When the 'Increment' Button is clicked..

hValueBox.Value += 1 'Increase the Value in the ValueBox by 1
Checks

End

Public Sub ButtonDec_Click() 'When the 'Decrement' Button is clicked..

hValueBox.Value -= 1 'Increase the Value in the ValueBox by 1
Checks

End

Public Sub Checks() 'Checks the values to see which controls to en/disable

If hValueBox.Value = 0 Then 'If the ValueBox = 0 then..
hValueBox.enabled = True 'Enable the control
Else 'Else..
hValueBox.enabled = False 'Disable the control
End If

If hValueBox.Value > 9 Then 'If the ValueBox greater than 9 then..
hButton0.enabled = False 'Disable the control
Else 'Else..
hButton0.enabled = True 'Enable the control
End If

If hValueBox.Value < 1 Then 'If the ValueBox less than 1 then..
hButton1.enabled = False 'Disable the control
Else 'Else..
hButton1.enabled = True 'Enable the control
End If

End

Public Sub ValBox_Leave() 'When the mouse leaves the ValueBox..

Checks 'Rune the Checks routine

End</lang>


==Icon and {{header|Unicon}}==
==Icon and {{header|Unicon}}==