private void CalibrateTarget(int calibrationId, QLCalibrationTarget target)
        {
            QLCalibrationStatus status = QLCalibrationStatus.QL_CALIBRATION_STATUS_OK;

            do
            {
                // Wait for a little bit so show the blanked screen.
                Thread.Sleep(100);

                // The target positions are in percentage of the area to be tracked so
                // we need to scale to the calibration window size.
                this.x          = Convert.ToInt32(Math.Truncate(target.x / 100 * this.Size.Width));
                this.y          = Convert.ToInt32(Math.Truncate(target.y) / 100 * this.Size.Height);
                this.drawTarget = true;

                //Draw a target
                this.Refresh();

                //Wait a little bit so the user can see the target before we calibrate.
                Thread.Sleep(250);

                // Calibrate the target for 1500 ms. This can be done two ways; blocking and
                // non-blocking. For blocking set the block variable to true. for
                // non-blocking set it to false.
                bool block = true;
                QuickLink2API.QLCalibration_Calibrate(calibrationId, target.targetId, 1500, block);

                // Get the status of the target.
                QuickLink2API.QLCalibration_GetStatus(calibrationId, target.targetId, out status);
            } while (status != QLCalibrationStatus.QL_CALIBRATION_STATUS_OK);
        }
            private bool CalibrateTarget(int targetIndex)
            {
                if (!this.Visible)
                {
                    this.Show();
                }

                if (!this.TopMost)
                {
                    this.TopMost = true;
                }

                if (this.WindowState != FormWindowState.Maximized)
                {
                    this.WindowState = FormWindowState.Maximized;
                }

                if (ActiveForm != this)
                {
                    this.Activate();
                }

                this._targetX = (int)Math.Truncate((this.Targets[targetIndex].x / 100f) * (float)this.Size.Width);
                this._targetY = (int)Math.Truncate((this.Targets[targetIndex].y / 100f) * (float)this.Size.Height);

                bool success = false;

                while (true)
                {
                    // Tell the picture box to draw the new target, and wait for it
                    // to wake us.
                    this._drawTarget = true;
                    this._calibrationPictureBox.Refresh();
                    lock (this._drawTargetLock)
                    {
                        while (this._drawTarget)
                        {
                            Monitor.Wait(this._drawTargetLock);
                        }
                    }

                    // Give the user time to look at the target.
                    Thread.Sleep(_delayTimePerTarget);

                    // Calibrate the target.
                    QLError error = QuickLink2API.QLCalibration_Calibrate(this._calibrationId, this.Targets[targetIndex].targetId, this._targetDuration, true);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_Calibrate() returned {0}.", error.ToString());
                        success = false;
                        break;
                    }

                    // Get the status of the last target.
                    QLCalibrationStatus status;
                    error = QuickLink2API.QLCalibration_GetStatus(this._calibrationId, this.Targets[targetIndex].targetId, out status);
                    if (error != QLError.QL_ERROR_OK)
                    {
                        Console.WriteLine("QLCalibration_GetStatus() returned {0}.", error.ToString());
                        success = false;
                        break;
                    }

                    if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_LEFT_DATA)
                    {
                        DialogResult result = MessageBox.Show("Left eye not found.  Retry?", "Left Eye Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_RIGHT_DATA)
                    {
                        DialogResult result = MessageBox.Show("Right eye not found.  Retry?", "Right Eye Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_NO_DATA)
                    {
                        DialogResult result = MessageBox.Show("Neither eye found.  Retry?", "Neither Eye Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result != DialogResult.Yes)
                        {
                            Console.WriteLine("User cancelled.");
                            success = false;
                            break;
                        }
                    }
                    else if (status == QLCalibrationStatus.QL_CALIBRATION_STATUS_OK)
                    {
                        success = true;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Calibration failed!");
                        success = false;
                        break;
                    }
                }

                return(success);
            }