/// <summary>
        /// Test decode program initialization
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnLoad(object sender, EventArgs e)
        {
            // program title
            Text = "QRCodeDecoderDemo - " + QRDecoder.VersionNumber + " \u00a9 2013-2018 Uzi Granot. All rights reserved.";

                #if DEBUG
            // current directory
            string CurDir  = Environment.CurrentDirectory;
            string WorkDir = CurDir.Replace("bin\\Debug", "Work");
            if (WorkDir != CurDir && Directory.Exists(WorkDir))
            {
                Environment.CurrentDirectory = WorkDir;
            }

            // open trace file
            QRCodeTrace.Open("QRCodeDecoderTrace.txt");
            QRCodeTrace.Write("QRCodeDecoderDemo");
                #endif

            // create decoder
            QRCodeDecoder = new QRDecoder();

            // resize window
            OnResize(sender, e);
            return;
        }
        private void OnLoadImage(object sender, EventArgs e)
        {
            // get file name to decode
            OpenFileDialog Dialog = new OpenFileDialog
            {
                Filter           = "Image Files(*.png;*.jpg;*.gif;*.tif)|*.png;*.jpg;*.gif;*.tif;*.bmp)|All files (*.*)|*.*",
                Title            = "Load QR Code Image",
                InitialDirectory = Directory.GetCurrentDirectory(),
                RestoreDirectory = true,
                FileName         = string.Empty
            };

            // display dialog box
            if (Dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // clear parameters
            ImageFileLabel.Text = Dialog.FileName;

            // disable buttons
            LoadImageButton.Enabled = false;

            // dispose previous image
            if (QRCodeInputImage != null)
            {
                QRCodeInputImage.Dispose();
            }

            // load image to bitmap
            QRCodeInputImage = new Bitmap(Dialog.FileName);

            // trace
                #if DEBUG
            QRCodeTrace.Format("****");
            QRCodeTrace.Format("Decode image: {0} ", Dialog.FileName);
            QRCodeTrace.Format("Image width: {0}, Height: {1}", QRCodeInputImage.Width, QRCodeInputImage.Height);
                #endif

            // decode image
            byte[][] DataByteArray = QRCodeDecoder.ImageDecoder(QRCodeInputImage);

            // display ECI value
            ECIValueLabel.Text = QRCodeDecoder.ECIAssignValue >= 0 ? QRCodeDecoder.ECIAssignValue.ToString() : null;

            // convert results to text
            DataTextBox.Text = QRCodeResult(DataByteArray);

            // enable buttons
            LoadImageButton.Enabled = true;

            // force repaint
            Invalidate();
            return;
        }
        private void QRCodeTimer_Tick(object sender, EventArgs e)
        {
            QRCodeTimer.Enabled = false;
            Bitmap QRCodeImage;

            try
            {
                QRCodeImage = VideoCamera.SnapshotSourceImage();

                // trace
                        #if DEBUG
                QRCodeTrace.Format("Image width: {0}, Height: {1}", QRCodeImage.Width, QRCodeImage.Height);
                        #endif
            }

            catch (Exception EX)
            {
                DataTextBox.Text    = "Decode exception.\r\n" + EX.Message;
                QRCodeTimer.Enabled = true;
                return;
            }

            // decode image
            byte[][] DataByteArray = Decoder.ImageDecoder(QRCodeImage);
            string   Text          = QRCodeResult(DataByteArray);

            // dispose bitmap
            QRCodeImage.Dispose();

            // we have no QR code
            if (Text.Length == 0)
            {
                QRCodeTimer.Enabled = true;
                return;
            }

            VideoCamera.PauseGraph();

            DataTextBox.Text    = Text;
            ResetButton.Enabled = true;
            if (IsValidUri(DataTextBox.Text))
            {
                GoToUriButton.Enabled = true;
            }
            return;
        }
        /// <summary>
        /// Program initialization
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        private void OnLoad(object sender, EventArgs e)
        {
            // program title
            Text = "QRCodeVideoDecoder - " + QRDecoder.VersionNumber + " \u00a9 2013-2018 Uzi Granot. All rights reserved.";

                #if DEBUG
            // current directory
            string CurDir  = Environment.CurrentDirectory;
            string WorkDir = CurDir.Replace("bin\\Debug", "Work");
            if (WorkDir != CurDir && Directory.Exists(WorkDir))
            {
                Environment.CurrentDirectory = WorkDir;
            }

            // open trace file
            QRCodeTrace.Open("QRCodeVideoDecoderTrace.txt");
            QRCodeTrace.Write(Text);
                #endif

            // disable reset button
            ResetButton.Enabled   = false;
            GoToUriButton.Enabled = false;

            // get an array of web camera devices
            DsDevice[] CameraDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            // make sure at least one is available
            if (CameraDevices == null || CameraDevices.Length == 0)
            {
                MessageBox.Show("No video cameras in this computer");
                Close();
                return;
            }

            // select the first camera
            DsDevice CameraDevice = CameraDevices[0];

            // Device moniker
            IMoniker CameraMoniker = CameraDevice.Moniker;

            // get a list of frame sizes available
            FrameSize[] FrameSizes = Camera.GetFrameSizeList(CameraMoniker);

            // make sure there is at least one frame size
            if (FrameSizes == null || FrameSizes.Length == 0)
            {
                MessageBox.Show("No video cameras in this computer");
                Close();
                return;
            }

            // test if our frame size is available
            int Index;
            for (Index = 0; Index < FrameSizes.Length &&
                 (FrameSizes[Index].Width != FrameSize.Width || FrameSizes[Index].Height != FrameSize.Height); Index++)
            {
                ;
            }

            // select first frame size
            if (Index == FrameSizes.Length)
            {
                FrameSize = FrameSizes[0];
            }

            // Set selected camera to camera control with default frame size
            // Create camera object
            VideoCamera = new Camera(PreviewPanel, CameraMoniker, FrameSize);

            // create QR code decoder
            Decoder = new QRDecoder();

            // resize window
            OnResize(sender, e);

            // create timer
            QRCodeTimer          = new Timer();
            QRCodeTimer.Interval = 200;
            QRCodeTimer.Tick    += QRCodeTimer_Tick;
            QRCodeTimer.Enabled  = true;
            return;
        }