示例#1
0
        public void OpenFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog OFD = new OpenFileDialog();
                OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                OFD.Filter           = "Photo Brush Project File (*.pbp)|*.pbp|Image File (*.png;*.jpg;*.tif;*.bmp;*.gif)|*.png;*.jpg;*.tif;*.bmp;*.gif|Adobe Photoshop Image (*.psd)|*.psd|All Files (*.*)|*.*";

                if (OFD.ShowDialog() == DialogResult.OK)
                {
                    switch (OFD.SafeFileName.Substring(OFD.SafeFileName.IndexOf('.')))
                    {
                    case ".png":
                    case ".jpg":
                    case ".tif":
                    case ".bmp":
                    case ".gif":
                        ImageHandlerForm IHF = new ImageHandlerForm(OFD.FileName, this);
                        IHF.Text = OFD.SafeFileName;//OFD.FileName.Remove(0, OFD.InitialDirectory.Length + 1);
                        //IHF.pictureBox1.Image = Image.FromFile(OFD.FileName);
                        Initialize(IHF, FormStyle.ImageHandleForm);
                        SetupDocumentEvents(IHF);
                        break;

                    case ".pbp":
                        PaintHandlerForm PHF = new PaintHandlerForm(this);
                        PHF.Text = OFD.SafeFileName;//OFD.FileName.Remove(0, OFD.InitialDirectory.Length + 1);
                        PHF.drawingCanvas1.shapeManager.FileName = OFD.FileName;
                        using (FileStream FS = new FileStream(OFD.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            BinaryFormatter BF = new BinaryFormatter();
                            ShapeManager    SM = (ShapeManager)BF.Deserialize(FS);
                            SM.RestoreNonSerializable(PHF.drawingCanvas1);
                            PHF.drawingCanvas1.shapeManager = SM;
                        }
                        PHF.drawingCanvas1.Invalidate();
                        Initialize(PHF, FormStyle.PaintHandleForm);
                        break;

                    case ".psd":
                        PsdHandlerForm PsdHF = new PsdHandlerForm();
                        PsdHF.Text = OFD.SafeFileName;
                        PsdHF.OpenPsdFile(OFD.FileName);
                        Initialize(PsdHF, FormStyle.PsdHandlerForm);
                        break;

                    default:
                        ReadyToolStripStatusLabel.Text = "Sorry cannot open this file !";
                        break;
                    }
                }
            }
            catch (Exception E) { MessageBox.Show(E.Message, "Error File", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
示例#2
0
        public void OpenFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog OFD = new OpenFileDialog();
                OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                OFD.Filter = "Photo Brush Project File (*.pbp)|*.pbp|Image File (*.png;*.jpg;*.tif;*.bmp;*.gif)|*.png;*.jpg;*.tif;*.bmp;*.gif|Adobe Photoshop Image (*.psd)|*.psd|All Files (*.*)|*.*";

                if (OFD.ShowDialog() == DialogResult.OK)
                {
                    switch(OFD.SafeFileName.Substring(OFD.SafeFileName.IndexOf('.')))
                    {
                        case ".png":
                        case ".jpg":
                        case ".tif":
                        case ".bmp":
                        case ".gif":
                        ImageHandlerForm IHF = new ImageHandlerForm(OFD.FileName, this);
                        IHF.Text = OFD.SafeFileName;//OFD.FileName.Remove(0, OFD.InitialDirectory.Length + 1);
                        //IHF.pictureBox1.Image = Image.FromFile(OFD.FileName);
                        Initialize(IHF, FormStyle.ImageHandleForm);
                        SetupDocumentEvents(IHF);
                        break;
                        case ".pbp":
                        PaintHandlerForm PHF = new PaintHandlerForm(this);
                        PHF.Text = OFD.SafeFileName;//OFD.FileName.Remove(0, OFD.InitialDirectory.Length + 1);
                        PHF.drawingCanvas1.shapeManager.FileName = OFD.FileName;
                        using (FileStream FS = new FileStream(OFD.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            BinaryFormatter BF = new BinaryFormatter();
                            ShapeManager SM = (ShapeManager)BF.Deserialize(FS);
                            SM.RestoreNonSerializable(PHF.drawingCanvas1);
                            PHF.drawingCanvas1.shapeManager = SM;
                        }
                        PHF.drawingCanvas1.Invalidate();
                        Initialize(PHF, FormStyle.PaintHandleForm);
                        break;
                        case ".psd":
                        PsdHandlerForm PsdHF = new PsdHandlerForm();
                        PsdHF.Text = OFD.SafeFileName;
                        PsdHF.OpenPsdFile(OFD.FileName);
                        Initialize(PsdHF, FormStyle.PsdHandlerForm);
                        break;
                        default:
                        ReadyToolStripStatusLabel.Text = "Sorry cannot open this file !";
                        break;
                    }
                }
            }
            catch (Exception E) { MessageBox.Show(E.Message, "Error File", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }