Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Help a VB Noob

Status
Not open for further replies.

IkeandMikes

Technical User
Jul 4, 2009
1
US
I have to make a simple program that changes the text of a button and hides a label on one click and then reverts back again when you click on it a second time. This has been driving me insane and any help is MUCH appreciated.
It's easy to get the things to change on one click, but to get them back without making another form or another button has been driving me crazy.
My simple code is such...

Public Class frmHideSeek

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

lblLanguage.Visible = False
btnDisplay.Text = "Changed "

End Sub
End Class

-- now what do I have to add to get it to change back when click the same button?
 
Public Class frmHideSeek

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles btnDisplay.Click
if lblLanguage.Visible =true then
'do other stuff here if you only want it to happen when you first click
btnDisplay.Text = "Changed"
Else
btnDisplay.Text = "Normal"
end if

lblLanguage.Visible = Not lblLanguage.Visible

End Sub
End Class
 
I agree with dilettante,

But your solution will probably be along the lines of:

Code:
Private Sub Button1_Click(.....)
  Label1.Visible = Not(Label1.Visible) ' Toggle Visibility
End Sub

Once you've sussed out how it toggles the visibility, you can expand the code...

Code:
Private Sub Button1_Click(.....)
  If Label1.Visible Then 'Label1 is visible, run the require code.
    'fire whatever Sub/Func/Proc
  Else
    'do whatever ELSE
  End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top