c# – Switch to a specific image by pressing a button


At the university we are making an application that allows us to play chess and our group decided that as part of the design and ease of play we will add an area where the rules of the game appear, including the movements of each piece.

We want that when pressing each button of the respective piece, the help image that is present in the interface, changes according to the button that the user has pressed there, that is, if the user presses the Rey button in the image that is present in the screen appears a photo with the possible movements of the Rey . And if you decide to press the Caballo button, the caballo 's movements now appear on the same image.

I have the images of the movements saved within the same solution in a specific folder Imágenes/Movimientos . Within the attached code is what we have so far to change the text contained in a .txt according to the button pressed and the ideal would be to do something similar to be able to change the image.

private void btnRey_Click(object sender, RoutedEventArgs e)
    this.txtMovimientos.Text = " El rey simboliza la cabeza del ejército, es decir, el mismo jugador. (El resto del texto no lo colocaré ya que se entiende la idea).";
    this.lblImagen1.Content = "";


To assign the image you could use

string imagePath = Path.Combine(Application.StartupPath, "Imágenes\Movimientos\Rey.jpg");

Picture.Image = Image.FromFile(imagePath);

in this way you could build the path to the image that you want to load in a picturebox to show it

Scroll to Top