Exemplo n.º 1
0
        private void toolStripButton_paste_Click(object sender, EventArgs e)
        {
            string strError = "";

            // 从剪贴板中取得图像对象
            List <Image> images = ImageUtil.GetImagesFromClipboard(out strError);

            if (images == null)
            {
                strError = "。无法进行粘贴";
                goto ERROR1;
            }
            Image image = images[0];

#if NO
            Image       image = null;
            IDataObject obj1  = Clipboard.GetDataObject();
            if (obj1.GetDataPresent(typeof(Bitmap)))
            {
                image = (Image)obj1.GetData(typeof(Bitmap));
            }
            else if (obj1.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])obj1.GetData(DataFormats.FileDrop);

                try
                {
                    image = Image.FromFile(files[0]);
                }
                catch (OutOfMemoryException)
                {
                    strError = "当前 Windows 剪贴板中的第一个文件不是图像文件。无法进行粘贴";
                    goto ERROR1;
                }
            }
            else
            {
                strError = "当前 Windows 剪贴板中没有图形对象。无法进行粘贴";
                goto ERROR1;
            }
#endif

            if (this.tabControl_main.SelectedTab == this.tabPage_clip)
            {
                ImageUtil.SetImage(this.pictureBox_clip, image);   // 2016/12/28
                if (this._pointsInitialized == false)
                {
                    this.pictureBox_clip.InitialPoints(image);
                    _pointsInitialized = true;
                }
            }
            if (this.tabControl_main.SelectedTab == this.tabPage_result)
            {
                this.Image = image;
            }

            return;

ERROR1:
            MessageBox.Show(this, strError);
        }