简体   繁体   中英

How to display multiple images in a single picturebox in c# windows form?

I'm a beginner in developing c# windows form in visual studio and i'm a little bit confused with its programming constructs compared to VB.NET that i'm used to program. I want to know how to display multiple images in a single picturebox because in vb.net you will just import the image then load it from the resources not like in c# that I think the coding is different. Any help would be appreciated.

I would create an ImageList with all the Images you want to show in your PictureBox, add the three Buttons to your Form and change the Picture on Click.

我的示例表格的图片

public partial class Form1 : Form
{

    private ImageList imagelst;

    public Form1()
    {
        InitializeComponent();
        imagelst = new ImageList();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //pictures from your Harddrive
        Image i = new Bitmap("rock.jpg");
        imagelst.Images.Add("rock", i);

        i = new Bitmap("scissors.jpg");
        imagelst.Images.Add("scissors", i);

        i = new Bitmap("paper.jpg");
        imagelst.Images.Add("paper", i);
    }

    private void btnRock_Click(object sender, EventArgs e)
    {
        pictureBox1.Image = imagelst.Images["rock"];
    }

    private void btnScissors_Click(object sender, EventArgs e)
    {
        pictureBox1.Image = imagelst.Images["scissors"];
    }

    private void btnPaper_Click(object sender, EventArgs e)
    {
        pictureBox1.Image = imagelst.Images["paper"];
    }
}

I hope I got what you want to do. If not excuse my bad english and slow-wittedness, please.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM