Exemple #1
0
        private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var settings   = configFile.AppSettings.Settings;

            if (settings["Directory"] == null)
            {
                MessageBox.Show("You should select path from folder selection in the toolbar");
                return;
            }
            else
            {
                if (!Directory.Exists(settings["Directory"].Value))
                {
                    MessageBox.Show("You should select path from folder selection in the toolbar");
                    return;
                }
                else
                {
                    // Determine the active child form
                    Object activeChild = (sender.GetType() == typeof(Form) || sender.GetType() == typeof(DisplayVideoForm) ? (sender.GetType() == typeof(DisplayVideoForm) ? (DisplayVideoForm)sender : (Form)sender) : this.ActiveMdiChild);

                    // If there is an active child form, find the active control
                    if (activeChild != null)
                    {
                        SaveFileDialog saveFileDialog = new SaveFileDialog();

                        if (activeChild.GetType() != typeof(DisplayVideoForm))
                        {
                            #region Save Image

                            CustomPictureBox pictureBox = (CustomPictureBox)((Form)activeChild).Controls[0];
                            if (pictureBox.isItSaved)
                            {
                                MessageBox.Show("It is already saved !");
                                return;
                            }
                            saveFileDialog.AddExtension     = true;
                            saveFileDialog.InitialDirectory = settings["Directory"].Value;
                            saveFileDialog.AddExtension     = true;
                            saveFileDialog.CheckPathExists  = true;
                            saveFileDialog.CheckFileExists  = false;
                            saveFileDialog.Filter           = "JPeg Image|*.jpg";
                            saveFileDialog.DefaultExt       = "jpg";
                            saveFileDialog.Title            = "Save an Image File...";
                            saveFileDialog.FileName         = $"Img_{ DateTime.Now.ToString("yyyyMMddmmhhssfff")}.jpg";
                            if (saveFileDialog.ShowDialog() == DialogResult.OK)
                            {
                                pictureBox.Image.Save(saveFileDialog.FileName);
                                pictureBox.isItSaved = true;
                                pictureBox.Refresh();
                                ((Form)activeChild).Text = ((Form)activeChild).Name = Path.GetFileName(saveFileDialog.FileName);
                            }
                            #endregion
                        }
                        else
                        {
                            #region Save Movie
                            AxWMPLib.AxWindowsMediaPlayer player = (AxWMPLib.AxWindowsMediaPlayer)((DisplayVideoForm)activeChild).Controls[0];

                            if (((DisplayVideoForm)activeChild).isItSaved)
                            {
                                MessageBox.Show("It is already saved !");
                                return;
                            }
                            saveFileDialog.AddExtension     = true;
                            saveFileDialog.InitialDirectory = settings["Directory"].Value;
                            saveFileDialog.AddExtension     = true;
                            saveFileDialog.CheckPathExists  = true;
                            saveFileDialog.CheckFileExists  = false;
                            saveFileDialog.Filter           = "Movie|*.avi";
                            saveFileDialog.DefaultExt       = "avi";
                            saveFileDialog.Title            = "Save an AVI File...";
                            saveFileDialog.FileName         = $"Video_{ DateTime.Now.ToString("yyyyMMddmmhhssfff")}.avi";
                            if (saveFileDialog.ShowDialog() == DialogResult.OK)
                            {
                                File.Copy(player.URL, saveFileDialog.FileName);
                                ((DisplayVideoForm)activeChild).isItSaved = true;
                                ((DisplayVideoForm)activeChild).Refresh();
                                ((DisplayVideoForm)activeChild).Text = ((DisplayVideoForm)activeChild).Name = Path.GetFileName(saveFileDialog.FileName);
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select form to save...");
                    }
                }
            }
        }
Exemple #2
0
        private void ShowNewForm(object sender, EventArgs e)
        {
            mainState        = this.WindowState;
            this.WindowState = FormWindowState.Minimized;
            GetReadyClipboard();
            this.Refresh();

            try
            {
                //
                // globalEventProvider1 -> add event
                //
                this.globalEventProvider1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(globalEventProvider1_KeyPress);

                Image clipboardImg = null;

                workerThread = new Thread(() => Operations.CaptureScreen(snippingToolFilePath, ref clipboardImg, ref escapeFired))
                {
                    IsBackground = true
                };
                workerThread.SetApartmentState(ApartmentState.STA);
                workerThread.Start();
                workerThread.Join();

                if (escapeFired)
                {
                    escapeFired = false;
                    this.globalEventProvider1.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(globalEventProvider1_KeyPress);

                    errorCount = 0;

                    this.WindowState = mainState;

                    //weird workaround
                    this.TopMost = true;
                    //it locks other forms to be front later on so
                    this.TopMost = false;

                    return;
                }

                fileName = $"Temporary Images\\{Guid.NewGuid().ToString()}.jpg";

                clipboardImg.Save(fileName, ImageFormat.Jpeg);

                //
                // pictureBox
                //
                CustomPictureBox pictureBox = new CustomPictureBox();
                pictureBox.Dock       = System.Windows.Forms.DockStyle.Fill;
                pictureBox.Location   = new System.Drawing.Point(0, 0);
                pictureBox.Name       = $"pictureBox_{DateTime.Now.ToString("yyyyMMddmmhhfff")}";
                pictureBox.TabStop    = false;
                pictureBox.Image      = Image.FromFile(fileName);
                pictureBox.ClientSize = pictureBox.Image.Size;
                pictureBox.Paint     += PictureBox_Paint;
                pictureBox.isItSaved  = false;

                //
                // Form
                //
                Form form = new Form();
                form.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
                form.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
                form.ClientSize          = pictureBox.ClientSize;
                form.Text = "*";
                form.Name = $"Form_{DateTime.Now.ToString("yyyyMMddmmhhfff")} * ";
                form.Controls.Add(pictureBox);
                form.ResumeLayout(false);
                form.Icon            = this.Icon;
                form.MaximizeBox     = false;
                form.MinimizeBox     = false;
                form.ControlBox      = false;
                form.FormBorderStyle = FormBorderStyle.FixedDialog;
                form.KeyDown        += Form_KeyDown;

                form.MdiParent = this;

                form.Show();

                this.ActiveControl = form;

                errorCount = 0;

                this.WindowState = mainState;

                //weird workaround
                this.TopMost = true;
                //it locks other forms to be front later on so
                this.TopMost = false;
                //because
                //this.TopLevel = true;
                //does not work.

                //
                // globalEventProvider1 -> remove event
                //
                this.globalEventProvider1.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(globalEventProvider1_KeyPress);

                if (workerThread.IsAlive)
                {
                    workerThread.Abort();
                }

                if (form.ClientSize.Width <= 131)
                {
                    MessageBox.Show("very small object is drawn. Image will be adjusted for the window but original size will be kept in case of recording", "Warning", MessageBoxButtons.OK);
                }

                return;
            }
            catch
            {
                this.WindowState = mainState;
                this.BringToFront();
                this.TopMost = true;

                MessageBox.Show(this, "Error is occured... Please try again !");
            }
        }