/// <summary>
        /// Start TableModule ==> Scan Button Was clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void ControlButton_Click(object sender, EventArgs e)
        {
            ScanButton sb = new ScanButton();

            // Get ScanButton instance depending on where the request came from
            if (sender is ToolStripMenuItem) // From Context Menu
            {
                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                sb = pbcms.parentButton;
            }
            else if (sender is ScanButton) // From LeftClick on ScanButton
            {
                sb = (ScanButton)sender;
            }
            else
            {
                throw new Exception("ControlButton_Click: Unknown Sender");
            }

            // Check Again for Size of the table
            checkEmulatorSize(sb.TableHandle);

            // Scan the table
            TableHandler.scan(sb);
        }
        public static void SeatingScript_Click(object sender, EventArgs e)
        {
            if (sender is ToolStripMenuItem)
            {
                SeatingScript ss = new SeatingScript();

                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                ScanButton scanButton            = pbcms.parentButton;

                if (tsi.Text.Equals(GlobalSettings.SeatingScript.StartSeatingScriptLabel))
                {
                    ss.startSeating(scanButton);
                    tsi.Text = GlobalSettings.SeatingScript.StopSeatingScriptLabel;
                }
                else if (tsi.Text.Equals(GlobalSettings.SeatingScript.StopSeatingScriptLabel))
                {
                    ss.stopSeating(scanButton);
                    tsi.Text        = GlobalSettings.SeatingScript.StartSeatingScriptLabel;
                    scanButton.Text = GlobalSettings.ButtonSettings.ScanButtonLabel;
                }
                else
                {
                    throw new Exception("Labeling of SeatingScript Buttons is wrong!");
                }
            }
            else
            {
                throw new Exception("Sender is no ToolStripMenuItem!");
            }
        }
        public void SetParent(IntPtr newParent)
        {
            this.TableHandle = newParent;
            ScanButtonContextMenuStrip sbcms = (ScanButtonContextMenuStrip)this.ContextMenuStrip;

            sbcms.tableHandle  = newParent;
            sbcms.parentButton = this;

            if (!TableHandle.Equals(IntPtr.Zero))
            {
                WinAPI.SetParent(this.Handle, TableHandle);
            }
        }
        private void LockAllButtons_Click(object sender, EventArgs e)
        {
            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                IntPtr    pointer = pbcms.tableHandle;
                TableData td      = TableHandler.tableSessions[pointer];

                // Lock Seats in TableData
                td.lockAllSeats();

                // Update Buttons => Show lock!
                string tablename        = td.tablename;
                PlayerButtonHandler pbh = TableHandler.buttonInventory[tablename];
                pbh.lockAllButtons();
            }
        }
        /// <summary>
        /// Attach ScanButton to Emulator instances
        /// </summary>
        public void attachScanControls()
        {
            updateSession(); // check for new emulator instances
            foreach (IntPtr emulator in emulatorList)
            {
                if (scanButtonList == null)
                {
                    scanButtonList = new Dictionary <IntPtr, ScanButton>();
                }

                // check if ScanButton for this emulator is already getting tracked
                if (scanButtonList.ContainsKey(emulator))
                {
                    continue;
                }
                //else Console.WriteLine("new emulator found");     // Debug

                // Check & Set Emulator Window Size
                checkEmulatorSize(emulator);

                // Init ScanButton with all necessary components (ComboBox for chosing tablesize, custom context menu, etc)
                ScanButton    scanButton         = new ScanButton();
                ScanComboBox  scanButtonComboBox = new ScanComboBox();
                AlertCheckBox box = new AlertCheckBox();
                ScanButtonContextMenuStrip scanButtonCMS = new ScanButtonContextMenuStrip();

                scanButton.ContextMenuStrip = scanButtonCMS;
                scanButton.scanComboBox     = scanButtonComboBox;
                scanButton.checkBox         = box;
                scanButton.TableName        = WinAPI.GetWindowTitle((int)emulator);
                scanButton.Click           += ControlButton_Click;

                scanButton.SetParent(emulator);
                scanButtonComboBox.SetParent(emulator);
                box.SetParent(emulator);

                // Add Emulator/Button to tracking
                scanButtonList[emulator] = scanButton;
            }
        }
        private void RemoveAllLocks_Click(object sender, EventArgs e)
        {
            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem          tsi   = (ToolStripMenuItem)sender;
                ScanButtonContextMenuStrip pbcms = (ScanButtonContextMenuStrip)tsi.GetCurrentParent();
                IntPtr    pointer = pbcms.tableHandle;
                TableData td      = TableHandler.tableSessions[pointer];

                // Unlock in TableData
                td.unlockAllSeats();

                // Unlock buttons => remove lock icons
                string tablename        = td.tablename;
                PlayerButtonHandler pbh = TableHandler.buttonInventory[tablename];
                pbh.removeAllLockImages();
            }
            else
            {
                throw new Exception("Sender is no ToolStripMenuItem!");
            }
        }