Beispiel #1
0
        private static void OpenSnipping()
        {
            formsWindow.HideAll();
            topMenuWindow.HideAll();
            selectorMenuWindow.HideAll();

            Task.Factory.StartNew(
                async() =>
            {
                var seconds = SettingsFeature.Settings.ScreenCaptureDelaySeconds;

                if (seconds == 0)
                {
                    // Give UI some time to hide top menu
                    await Task.Delay(TimeSpan.FromSeconds(0.25f));
                }
                else
                {
                    await Task.Delay(TimeSpan.FromSeconds(seconds));
                }

                SnippingWindow.ShowInEveryMonitor(UIActionSelected);
            },
                CancellationToken.None,
                TaskCreationOptions.None,
                TaskScheduler.FromCurrentSynchronizationContext());
        }
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // mandatory filename arg - grabbed output will write to this file.
            if (e.Args.Length == 1 && !string.IsNullOrEmpty(e.Args[0]))
            {
                string filename = e.Args[0];
                var    win      = new SnippingWindow(filename);
                win.Show();
            }
            // or Openfin port and app UUID
            else if (e.Args.Length == 3 && !string.IsNullOrEmpty(e.Args[0]) && !string.IsNullOrEmpty(e.Args[1]) && !string.IsNullOrEmpty(e.Args[2]))
            {
                int port;

                if (!int.TryParse(e.Args[0], out port) || port < 1 || port > 65535)
                {
                    throw new Exception("Invalid port number.");
                }

                var uuid  = e.Args[1];
                var topic = e.Args[2];

                var win = new SnippingWindow(port, uuid, topic);
                win.Show();
            }
            else
            {
                throw new Exception("Invalid command line arguments.");
            }
        }
Beispiel #3
0
        ///<summary>Minimizes the form and calls the child form (SnippingWindow). The child form takes a screenshot of the users
        ///monitors and overlays it with an opaque rectangle. The user can then highlight subsections of that rectangle to "snip"
        ///that portion of the captured screen. The child form has a public variable that the parent form uses to access the snipped image.</summary>
        private void buttonNewSnip_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            //This arbitrary wait is to give the form time to complete its minimization animation. We do not want this form to show up in the
            //screenshot so this is necessary. We cannot utilize the Form_Resized() event as that also happens too quickly and still catches the window.
            //Because this wait time is machine dependent we may need to change it in the future if customers start to complain.
            System.Threading.Thread.Sleep(300);
            //Creates a rectangle object spanning all screens connected to the system.
            Rectangle totalScreenSize = Rectangle.Empty;

            //We could use virtual screen but that may not work for all windows versions.
            foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens)
            {
                totalScreenSize = Rectangle.Union(totalScreenSize, s.Bounds);
            }
            using (Bitmap currentScreenCapture = new Bitmap(totalScreenSize.Width, totalScreenSize.Height, PixelFormat.Format32bppPArgb)) {
                using (Graphics g = Graphics.FromImage(currentScreenCapture)) {
                    //Print screen into currentScreenCapture
                    g.CopyFromScreen(0, 0, 0, 0, currentScreenCapture.Size);
                }
                SnippingWindow FormODS = new SnippingWindow(currentScreenCapture);
                FormODS.ShowDialog();
                if (FormODS.DialogResult == DialogResult.OK)
                {
                    SnippedScreenshot = FormODS.SnippedScreenshot;
                    pictureBox1.Image = SnippedScreenshot;
                    //Show the parent form again
                    this.WindowState = FormWindowState.Normal;
                    pictureBox1.Size = SnippedScreenshot.Size;
                    //This is a hack to make the snipped image look centered if it is smaller than the forms default size.
                    //For whatever reason the form's autosize logic does not trigger when the picturebox is smaller than the form.
                    int widthPad = 25;
                    if (this.Size.Width > pictureBox1.Size.Width + widthPad)
                    {
                        pictureBox1.Size = new System.Drawing.Size(this.Size.Width - widthPad, this.pictureBox1.Size.Height);
                    }
                    RelayoutForm();
                }
                if (FormODS.DialogResult == DialogResult.Cancel)               //Cancel out of the snipper entirely if they cancelled while snipping.
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }
        }
Beispiel #4
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            string[] availableLocale = { "en-US", "ja-JP", "fr-FR" };

            string filename = (e.Args.Length >= 1 && !string.IsNullOrEmpty(e.Args[0])) ? e.Args[0] : null;
            string locale   = (e.Args.Length == 2 && !string.IsNullOrEmpty(e.Args[1])) ? e.Args[1] : null;

            if (filename != null)
            {
                if (locale != null && availableLocale.Contains(locale))
                {
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(locale);
                }
                SnippingWindow win = new SnippingWindow(filename);
                win.Show();
            }
            else
            {
                throw new Exception("Missing filename command line argument.");
            }
        }