以表格形式显示图片 [英] showing pictures in form

查看:322
本文介绍了以表格形式显示图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我编写了一些代码以另一种形式显示图片,当我选择一张图片但要选择3张图片并全部显示时,此代码会谨慎执行.

Hi all
I write some code to show picture in another form and this code do carefully when I select one picture but I want to select 3 picture and show all of them.

        private void ItmopenMultiplyFiles_Click(object sender, EventArgs e)
{
    openFileDialog1.Multiselect = true;
    openFileDialog1.FileName = string.Empty;
    openFileDialog1.InitialDirectory = @"C:\Users\yonesi\Desktop\Resources";
    openFileDialog1.Filter = "Bitmap Files|*.bmp|jpeg Files|*.jpg;*.jpeg|All Files|*.*";
    openFileDialog1.ShowDialog();
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        string a = openFileDialog1.FileName;
        string b = Path.GetFileName(a);
        PictureForm frmpic = new PictureForm();
        frmpic.Text = b;
        foreach (string c in openFileDialog1.FileNames)
        {
            frmpic.pictureBox1.Image = Image.FromFile(a);
            frmpic.Show();
        }
    }
}



[edit]添加了代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

然后,您将需要将PictureBox添加到frmPic,或使用多个frmPic实例-每个实例一个图片:
Then you will either need to add PictureBoxes to frmPic, or use multiple instances of frmPic - one for each image:
foreach (string c in openFileDialog1.FileNames)
    {
    MyPictureForm frmpic = new MyPictureForm();
    frmpic.pictureBox1.Image = Image.FromFile(a);
    frmpic.Show();
    }


{
            openFileDialog1.Multiselect = true;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.InitialDirectory = @"C:\Users\yonesi\Desktop\Resources";
            openFileDialog1.Filter = "Bitmap Files|*.bmp|jpeg Files|*.jpg;*.jpeg|All Files|*.*";
           
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (string c in openFileDialog1.FileNames)
                {
                string b = Path.GetFileName(c);
                PictureForm frmpic = new PictureForm();
                frmpic.Text = b
                frmpic.pictureBox1.Image = Image.FromFile(c);
                frmpic.MdiParent=this;
                frmpic.Show();
                }
            }


这篇关于以表格形式显示图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆