Link to home
Start Free TrialLog in
Avatar of NCSO
NCSO

asked on

Change Label text with click events

Experts,

I have a label (label1) on my form and its text value is “View Details”.  What I would like to do is if the user clicks on the view details label; one, change the label1.text value to “Hide Details” and show groupbox1; secondly, if the user now clicks on the label1.text value of “ Hide Details”, make groupbox1.visibility = false and label1.text value back to “View Details”

I currently have the following code but I can not figure out how to make the next click event revert back to the original of groupbox1.visible = false and label1.text = “View Details”

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        GroupBox1.Visible = True
        Label1.Text = "Hide Details"

    End Sub

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hit_MN
Hit_MN


I agree with emoreau post (so, no points to me... :D ), but I would do it like this:

If GroupBox1.Visible = True Then
        GroupBox1.Visible = False
        Label1.Text = "Show Details"
Else
        GroupBox1.Visible = True
        Label1.Text = "Hide Details"
End If

HTH,
Marco
Avatar of NCSO

ASKER

emoreau,

It works, Kinda!  

I click view details and groupbox is visible and the label text changes to hide details

I now click on Hide details and the groupbox is not visible and the text changes to Show, not show details
>>and the text changes to Show, not show details

is your label large enough  ?

Avatar of NCSO

ASKER

Hit MN,

Same problem with yours
Avatar of NCSO

ASKER

yes, if I change the text to showdetails with no space I see it

I have tried Label1.Text = "show" + " " + "Details"  No luck either
your label is definetly not large enough

can you paste you code please?
Avatar of NCSO

ASKER

How is the space between the show and the details making the details section not visible?  I want to clarify my earlier statement, if I change the text to label1.text="ShowDetails" I get ShowDetails, not the desired Show Details

Well... set label1.AutoSize = True at design time...
Avatar of NCSO

ASKER

BINGO, label not big enough
Avatar of NCSO

ASKER

Great Job!  Thanks for you assistance.  "Hit MN", you were also correct.  However "emoreau" declared first with same solution