ScreenToGif.Windows.Recorder.RecordPause C# (CSharp) Method

RecordPause() private method

Method that starts or pauses the recording
private RecordPause ( ) : void
return void
        private void RecordPause()
        {
            Extras.CreateTemp(_pathTemp);

            switch (Stage)
            {
                case Stage.Stopped:

                    #region To Record

                    _capture = new Timer { Interval = 1000 / (int)FpsNumericUpDown.Value };
                    _snapDelay = null;

                    ListFrames = new List<FrameInfo>();
                    UpdateScreenDpi();

                    #region If Fullscreen

                    if (Settings.Default.FullScreen)
                    {
                        _size = new System.Drawing.Size((int)_sizeScreen.X, (int)_sizeScreen.Y);

                        HideWindowAndShowTrayIcon();

                        //TODO: Hide the top of the window, add a little drag component, position this window at the bottom.
                    }
                    else
                    {
                        _size = new System.Drawing.Size((int)((Width - Constants.HorizontalOffset) * _scale), (int)((Height - Constants.VerticalOffset) * _scale));
                    }

                    #endregion

                    HeightTextBox.IsEnabled = false;
                    WidthTextBox.IsEnabled = false;
                    FpsNumericUpDown.IsEnabled = false;

                    IsRecording(true);
                    Topmost = true;

                    FrameRate.Start(_capture.Interval);
                    UnregisterEvents();

                    #region Start

                    if (Settings.Default.PreStart)
                    {
                        Title = $"Screen To Gif ({FindResource("Recorder.PreStart")} 2s)";
                        RecordPauseButton.IsEnabled = false;

                        Stage = Stage.PreStarting;
                        _preStartCount = 1; //Reset timer to 2 seconds, 1 second to trigger the timer so 1 + 1 = 2

                        _preStartTimer.Start();
                    }
                    else
                    {
                        if (Settings.Default.ShowCursor)
                        {
                            #region If Show Cursor

                            if (!Settings.Default.FullScreen)
                            {
                                //To start recording right away, I call the tick before starting the timer,
                                //because the first tick will only occur after the delay.
                                _capture.Tick += Cursor_Elapsed;
                                //Cursor_Elapsed(null, null);
                                _capture.Start();
                            }
                            else
                            {
                                _capture.Tick += FullCursor_Elapsed;
                                //FullCursor_Elapsed(null, null);
                                _capture.Start();
                            }

                            Stage = Stage.Recording;

                            AutoFitButtons();

                            #endregion
                        }
                        else
                        {
                            #region If Not

                            if (!Settings.Default.FullScreen)
                            {
                                _capture.Tick += Normal_Elapsed;
                                //Normal_Elapsed(null, null);
                                _capture.Start();
                            }
                            else
                            {
                                _capture.Tick += Full_Elapsed;
                                //Full_Elapsed(null, null);
                                _capture.Start();
                            }

                            Stage = Stage.Recording;

                            AutoFitButtons();

                            #endregion
                        }
                    }
                    break;

                #endregion

                #endregion

                case Stage.Recording:

                    #region To Pause

                    Stage = Stage.Paused;
                    Title = FindResource("Recorder.Paused").ToString();

                    DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose);

                    AutoFitButtons();

                    _capture.Stop();

                    FrameRate.Stop();
                    break;

                #endregion

                case Stage.Paused:

                    #region To Record Again

                    Stage = Stage.Recording;
                    Title = "Screen To Gif";

                    DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose);

                    AutoFitButtons();

                    FrameRate.Start(_capture.Interval);

                    _capture.Start();
                    break;

                    #endregion
            }
        }