Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要重新绘制的图片盒。 namespace WindowsFormsApplication1 { public partial class Form1 : Form { ArrayList alist = new ArrayL_C#_Winforms_Picturebox - Fatal编程技术网

C# 要重新绘制的图片盒。 namespace WindowsFormsApplication1 { public partial class Form1 : Form { ArrayList alist = new ArrayL

C# 要重新绘制的图片盒。 namespace WindowsFormsApplication1 { public partial class Form1 : Form { ArrayList alist = new ArrayL,c#,winforms,picturebox,C#,Winforms,Picturebox,要重新绘制的图片盒。 namespace WindowsFormsApplication1 { public partial class Form1 : Form { ArrayList alist = new ArrayList(); int i = 0; int filelength = 0; public Form1() { InitializeComponent();

要重新绘制的图片盒。
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ArrayList alist = new ArrayList();
        int i = 0;
        int filelength = 0;
        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            DirectoryInfo di = new      DirectoryInfo(@"C:\Users\Arun\Desktop\scanned");
            DirectoryInfo[] folders = di.GetDirectories();
            comboBox1.DataSource = folders;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (i + 1 < filelength)
            {
                pictureBox1.Image = Image.FromFile(alist[i + 1].ToString());
                i = i + 1;
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {

            if (i - 1 >= 0)
            {

                pictureBox1.Image = Image.FromFile(alist[i - 1].ToString());
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                i = i - 1;
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selected = comboBox1.SelectedItem.ToString();
            String fullpath = Path.Combine(@"C:\Users\Arun\Desktop\scanned", selected);
            DirectoryInfo di1 = new DirectoryInfo(fullpath);
            DirectoryInfo[] folders1 = di1.GetDirectories();
            comboBox2.DataSource = folders1;

        }

        private void button9_Click(object sender, EventArgs e)
        {

            string selected1 = comboBox1.SelectedItem.ToString();
            string selected2 = comboBox2.SelectedItem.ToString();

                        //Initially load all your image files into the array list when form load first time
            System.IO.DirectoryInfo inputDir = new System.IO.DirectoryInfo(Path.Combine(@"C:\Users\Arun\Desktop\scanned", selected1, selected2)); //Source image folder path


            try
            {


                if ((inputDir.Exists))
                {

                    //Get Each files 
                    System.IO.FileInfo file = null;
                    foreach (System.IO.FileInfo eachfile in inputDir.GetFiles())
                    {
                        file = eachfile;
                        if (file.Extension == ".tif")
                        {
                            alist.Add(file.FullName); //Add it in array list
                            filelength = filelength + 1;
                        }
                        else if(file.Extension == ".jpg")
                        {

                            alist.Add(file.FullName); //Add it in array list
                            filelength = filelength + 1;
                        }
                    }

                    pictureBox1.Image = Image.FromFile(alist[0].ToString());  //Display intially first image in picture box as sero index file path
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    i = 0;

                }
            }
            catch (Exception ex)
            {

            }

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.D)
            {
                if (i + 1 < filelength)
                {
                    pictureBox1.Image = Image.FromFile(alist[i + 1].ToString());
                    i = i + 1;
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                }
            }
            else if(e.KeyCode == Keys.A)
            {
                if (i - 1 >= 0)
                {

                    pictureBox1.Image = Image.FromFile(alist[i - 1].ToString());
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    i = i - 1;
                }
            }
        }


        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

  }
}
    alist.Clear();
    //Get Each files 
   filelength = alist.Count;
List<string> alist = new List<string>();
void loadImage(PictureBox pbox, string file)
{
    if (pbox.Image != null)
    {
        var dummy = pbox.Image;
        pbox.Image = null;
        dummy.Dispose();
    }
    if (File.Exists(file)) pbox.Image = Image.FromFile(file);
}