Havel The Gravel
Havel The Gravel

Reputation: 21

How can I make a pictureBox that, when clicked, will display some text to a label?

I'm using Visual Studio, so I already have drag-and-dropped some pictureBoxes in there, and they have names and pictures. I just want to be able to click them and have a label say the name of the person in the picture that was clicked.

This is what I currently have (for the pictureBox only)

private void captainFalcon_Click(object sender, EventArgs e)  
{  
    Label.Show("Captain Falcon");  

}

FINAL EDIT: Everything is working now, I just followed everyone's suggestions!

Upvotes: 1

Views: 1674

Answers (3)

Reza Aghaei
Reza Aghaei

Reputation: 125257

Use

private void captainFalcon_Click(object sender, EventArgs e)
{
    xxxxxx.Text ="Captain Falcon";
}

and instead of xxxxx use your label name.
Select your label on designer, look at its properties, and use its "(Name)" property.

For example if your label name is characterName, then your code will be

characterName.Text ="Captain Falcon";

Upvotes: 1

Magic Mick
Magic Mick

Reputation: 1533

Something like below will work.

private void pictureBox1_Click(object sender, EventArgs e)
{
    label1.Text = "Captain Falcon";
}

Obviously change the control names (pictureBox1 and label1) to match yours.

Upvotes: 1

Enigmativity
Enigmativity

Reputation: 117144

Is this what you need?

private void captainFalcon_Click(object sender, EventArgs e)
{
    Label.Text = "Captain Falcon";
}

Upvotes: 1

Related Questions