Exemplo n.º 1
0
        void MainForm_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.None;
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if(files != null && files.Length == 1)
                    e.Effect = DragDropEffects.Copy;
            }
            else
            {
                //wrap standard IDataObject in OutlookDataObject
                OutlookDataObject dataObject = new OutlookDataObject(e.Data);

                //get the names and data streams of the files dropped
                string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor");
                if (filenames.Length == 1 && IsPdfFileName(filenames[0]))
                    e.Effect = DragDropEffects.Copy;
            }
        }
Exemplo n.º 2
0
        void MainForm_DragDrop(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.None;
            string newFileName;
            bool isTempFile;
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                newFileName = files[0];
                isTempFile = false;
            }
            else
            {
                //wrap standard IDataObject in OutlookDataObject
                OutlookDataObject dataObject = new OutlookDataObject(e.Data);

                //get the names and data streams of the files dropped
                string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor");

                if (filenames.Length != 1 || !IsPdfFileName(filenames[0]))
                    return;
                MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
                isTempFile = true;
                newFileName = Path.GetTempFileName() + filenames[0];

                try
                {
                    FileInfo fileInfo = new FileInfo(fileName);
                    FileStream tempFileStream = File.Create(fileName);
                    fileInfo.Attributes = FileAttributes.Temporary;
                    filestreams[0].WriteTo(tempFileStream);
                    tempFileStream.Close();
                }
                catch (System.Exception ex)
                {
                    ShowError(ex.Message);
                }
            }
            try
            {
                CloseDocument();
                tempFile = isTempFile;
                fileName = newFileName;
                document = new AcroAVDoc();
                document.Open(fileName, "");
                document.BringToFront();
                document.SetViewMode(2); // PDUseThumbs
                CAcroAVPageView pageView = document.GetAVPageView() as CAcroAVPageView;
                pageView.ZoomTo(1 /*AVZoomFitPage*/, 100);
            }
            catch (System.Exception ex)
            {
                ShowError(ex.Message);
                fileName = null;
                tempFile = false;
            }
        }