Hi ,,,

I need your help plz...

i have programed a calculator and i have an On\Of button .

when the user click On\Off button i want to disable all buttons i have except On\Of button, But also I need to enable all buttons when the user click it again.

and i do not want to use any decision constructs.

i need ur help as soon as possible plz ..


i am beginner in VB

Thank you

Dani AI

Generated

A concise, maintainable fix is to group all calculator buttons and input controls into a single container (Panel or GroupBox) and toggle that container’s Enabled property from the On/Off click handler. This keeps the handler to a single statement, requires no decision constructs in the click event, and avoids the long manual list shown earlier in the thread (as posted by ). ’s boolean toggle is compact and works; grouping simply makes future changes safer.

Private Sub btnOnOff_Click(sender As Object, e As EventArgs) Handles btnOnOff.Click
    pnlCalculator.Enabled = Not pnlCalculator.Enabled
End Sub

Place btnOnOff outside pnlCalculator so it remains clickable when the panel is disabled. New buttons added to the panel automatically follow the panel state.

If controls are spread across multiple containers, use a small recursive helper to flip Enabled for Buttons and TextBoxes while skipping the On/Off button:

Private Sub ToggleControls(root As Control, skip As Control)
    For Each c As Control In root.Controls
        If c Is skip Then Continue For
        If TypeOf c Is Button Or TypeOf c Is TextBox Then c.Enabled = Not c.Enabled
        If c.HasChildren Then ToggleControls(c, skip)
    Next
End Sub

' from the click handler:
ToggleControls(Me, btnOnOff)

Additional notes: consider setting the display textbox to ReadOnly instead of disabling it so results remain copyable; initialize the panel’s Enabled state on form load; and prefer logical grouping (panels) for maintainability and accessibility. This approach keeps the On/Off logic simple, avoids extensive manual edits, and scales cleanly as the calculator UI grows.

Recommended Answers

All 9 Replies

If I am understanding correctly, this might help you.

Disables a Button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button2.Enabled = false
    End Sub

Enables a button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button2.Enabled = True
    End Sub

If not let me know. :)

thank you for fast replaying ..

i think i will need to make my question clear .

Private Sub btnOnOF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOnOF.Click
        btnAddition.Enabled = False
        btnDivision.Enabled = False
        btnEq.Enabled = False
        btnSubtruction.Enabled = False
        btnMod.Enabled = False
        btnSqrRoot.Enabled = False
        btnMultiplication.Enabled = False
        btnMRec.Enabled = False
        btnMSt.Enabled = False
        txtFstNum.Enabled = False
        txtOutput.Enabled = False
        txtSecNum.Enabled = False

    End Sub

at this moment i have disable all the buttons except On\Of button ..

and now i need to enable them when the user click on On\of button...

what i should do ..

What I think you might need is an Enable_Change Event. I will try and put something together and try to help you if no one beats me to it.
:)

okay thank you >>


i am waiting your replay..

Dim flag as boolean=False
Private Sub btnOnOF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOnOF.Click
if flag=Flase then
        btnAddition.Enabled = False
        btnDivision.Enabled = False
        btnEq.Enabled = False
        btnSubtruction.Enabled = False
        btnMod.Enabled = False
        btnSqrRoot.Enabled = False
        btnMultiplication.Enabled = False
        btnMRec.Enabled = False
        btnMSt.Enabled = False
        txtFstNum.Enabled = False
        txtOutput.Enabled = False
        txtSecNum.Enabled = False
flag=True
else
        btnAddition.Enabled = True
        btnDivision.Enabled = True
        btnEq.Enabled = True
        btnSubtruction.Enabled = True
        btnMod.Enabled = True
        btnSqrRoot.Enabled = True
        btnMultiplication.Enabled = True
        btnMRec.Enabled = True
        btnMSt.Enabled = True
        txtFstNum.Enabled = True
        txtOutput.Enabled = True
        txtSecNum.Enabled = True
flag=True
end if
    End Sub

I hope it will help you

Thank you for replaying ,,,


But, i want to solve this question without using any decision constructs

Thank you

Dim flag As Boolean = False

Private Sub btnOnOF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOnOF.Click
        btnAddition.Enabled = flag
        btnDivision.Enabled = flag
        btnEq.Enabled = flag
        btnSubtruction.Enabled = flag
        btnMod.Enabled = flag
        btnSqrRoot.Enabled = flag
        btnMultiplication.Enabled = flag
        btnMRec.Enabled = flag
        btnMSt.Enabled = flag
        txtFstNum.Enabled = flag
        txtOutput.Enabled = flag
        txtSecNum.Enabled = flag
        flag = Not flag
    End Sub

I this you want.........I think so

commented: Thank you +1

wowo


Thank you very much prvnkmr194 my problem has been solved

Most Welcome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.