Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Jpg files (*.jpg)|*.jpg";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            String FileName = "";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    FileName      = openFileDialog1.FileName;
                    textBox1.Text = FileName;
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        teacherImg = StreampTo32bppArgbBitmap(myStream);
                        myStream.Close();
                        int w = teacherImg.Width;
                        int h = teacherImg.Height;
                        textBox3.Text = FileName + " (" + w + "x" + h + ")";
                        ImageForm browser = new ImageForm();
                        browser.config(w, h, teacherImg);
                        browser.Show();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("無法開啟" + FileName + ":\n" + ex.Message);
                    textBox1.Text = "";
                }
            }
        }