Ejemplo n.º 1
0
        private void CaptureButton_Click(object sender, EventArgs e)
        {
            Screen selectedScreen;

            if (Screen.AllScreens.Length > 1)
            {
                using (var dialog = new SelectScreenDialog())
                {
                    dialog.ShowDialog(ParentForm);
                    selectedScreen = dialog.SelectedScreen;
                }
            }
            else
            {
                selectedScreen = Screen.PrimaryScreen;
            }
            using (var dialog = new CaptureAreaDialog(selectedScreen))
            {
                ParentForm.Hide();
                dialog.ShowDialog(ParentForm);
                ParentForm.Show();
                var area = dialog.CaptureArea;
                if (area.Width == 0 || area.Height == 0)
                {
                    return;
                }
                Observer.CaptureX      = area.X;
                Observer.CaptureY      = area.Y;
                Observer.CaptureWidth  = area.Width;
                Observer.CaptureHeight = area.Height;
                RefreshView();
            }
        }
Ejemplo n.º 2
0
        private void bttn_Play_Click(object sender, EventArgs e)
        {
            var PlJugar = new PlayerNickname();

            PlJugar.Show();
            ParentForm.Hide();
        }
Ejemplo n.º 3
0
        private void btnLogout_Click(object sender, EventArgs e)
        {
            Login frmLogin = new Login();

            frmLogin.Show();
            ParentForm.Hide();
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Account user = new Account();

            if (user_in.Text == "Username" || pass_in.Text == "Password")
            {
                MessageBox.Show("Please enter all information", "Error to Sign in", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                user.Username = user_in.Text.Trim();
                user.Password = pass_in.Text.Trim();

                int count = user.Check_account();
                if (count == 1)     //if username or email and password are correct (count is the return of "Check_account" method in Account class)
                {
                    Homepage f2 = new Homepage();
                    userName = user_in.Text;
                    f2.Show();
                    f2.WindowState = FormWindowState.Normal;
                    ParentForm.Hide();
                }
                else
                {
                    MessageBox.Show("Your username or password is incorrect", "Incorrect username or password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
        private void bt_registar_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] msg = Encoding.UTF8.GetBytes(tb_username.Text + "_Ø_" + tb_password.Text);


                //verificar se a resposta do servidor é OK
                if (EnviarDadosServidor(ProtocolSICmdType.USER_OPTION_2, msg) == 1 && LerRespostaServidor())
                {
                    ParentForm.Hide();

                    Form_Autenticar.nickname = tb_username.Text;

                    Form_Jogo form = new Form_Jogo();
                    form.ShowDialog();

                    /*FormPrincipal form = new FormPrincipal(TextBoxUsername);
                     * form.ShowDialog();*/
                }
                else // ou se a resposta é NOK
                {
                    lb_validar.Visible = true;
                }
            }
            catch (SocketException)
            {
                MessageBox.Show("Não foi possivel conectar ao servidor tente outra vez");
                return;
            }
        }
Ejemplo n.º 6
0
        private void TBsearch_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Down:
                updateSelectedIndex(selectedIndex + 1);
                break;

            case Keys.Up:
                updateSelectedIndex(selectedIndex - 1);
                break;

            case Keys.Enter:
                var code = controls[selectedIndex].Code;
                ParentForm.Hide();
                KeyHandler.sendString(UTF8Helper.hexStringToLetter(code));
                break;

            case Keys.Escape:
                ParentForm.Hide();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 7
0
        private void done_option_Click(object sender, EventArgs e)
        {
            ParentForm.Hide();
            IListener udplistener = new UDPListener(textAddr.Text, int.Parse(waterMarkTextBox1.Text));
            ISender   udpsender   = new UDPSender(textAddr.Text, int.Parse(waterMarkTextBox1.Text));
            GameArea  game        = new GameArea(ParentForm, udplistener, udpsender);

            game.Show();
        }
 protected virtual void OnLaunchSession(LaunchSessionEventArgs se)
 {
     if (LaunchSession != null)
     {
         // Hide the form if the option has been requested
         if (Properties.Settings.Default.MinimizeOnUse == true && ParentForm.Visible)
         {
             ParentForm.Hide();
         }
         LaunchSession(this, se);
     }
 }
Ejemplo n.º 9
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            var collection = database.GetCollection <BsonDocument>("comments");
            var builder    = Builders <BsonDocument> .Filter;
            var filter     = builder.Eq("_id", ObjectId.Parse(commentId));
            var result     = collection.DeleteOne(filter);

            ParentForm.Hide();
            comment com = new comment(postId);

            com.Show();
        }
Ejemplo n.º 10
0
        private void LoadPanel(Model.User user)
        {
            var adminRole = user.UserRoles.FirstOrDefault(i => i.Role.Name == "Administrator");

            if (adminRole != null)
            {
                var form = new frmAdminPanel(user);
                form.Show();

                ParentForm.Hide();
            }
        }
        private void _btnPoint_Click(object sender, EventArgs e)
        {
            if (EnablePointSelection != null)
            {
                //send event to allow interfacing to CTCGui
                EnablePointSelection(this, EventArgs.Empty);
            }

            //hide this gui
            ParentForm.Hide();
            //show ctc gui
            _ctcGui.Show();
        }
Ejemplo n.º 12
0
 private void Save_btn_Click(object sender, EventArgs e)
 {
     if (Year_txt.Text == "" || Six_M_txt.Text == "" || three_M_txt.Text == "" || one_M_txt.Text == "")
     {
         MessageBox.Show("Please enter all data !", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         Main F = new Main();
         F.Show();
         ParentForm.Hide();
     }
 }
Ejemplo n.º 13
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            var collection = database.GetCollection <BsonDocument>("posts");
            var builder    = Builders <BsonDocument> .Filter;
            var filter     = builder.Eq("_id", ObjectId.Parse(postId));
            var result     = collection.DeleteOne(filter);

            ParentForm.ParentForm.Hide();
            ParentForm.Hide();
            Menu menu = new Menu();

            menu.OpenChildForm(new Timeline());
            menu.Show();
        }
Ejemplo n.º 14
0
 protected virtual void OnLaunchSession(LaunchSessionEventArgs se)
 {
     if (LaunchSession != null)
     {
         // Hide the form if the option has been requested
         if (Properties.Settings.Default.MinimizeOnUse == true)
         {
             if (ParentForm is SessionManagerForm)
             {
                 ((SessionManagerForm)ParentForm).hideApplication();
             }
             else
             {
                 ParentForm.Hide();
             }
         }
         LaunchSession(this, se);
     }
 }
Ejemplo n.º 15
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            var screen = Screen.FromPoint(new Point(Observer.CaptureX, Observer.CaptureY));
            var area   = new Rectangle(Observer.CaptureX, Observer.CaptureY, Observer.CaptureWidth, Observer.CaptureHeight);

            if (screen.Bounds.IntersectsWith(area))
            {
                using (var dialog = new ConfirmAreaDialog(screen, area))
                {
                    ParentForm.Hide();
                    dialog.ShowDialog(ParentForm);
                    ParentForm.Show();
                }
            }
            else
            {
                using (var centerAligner = new DialogCenterAligner(ParentForm))
                {
                    MessageBox.Show(ParentForm, Resources.AreaOutOfRange, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 16
0
        private void done_option_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textAddr.Text) || string.IsNullOrWhiteSpace(textPort.Text))
            {
                MessageBox.Show("Please enter an IP Address and/or Port Number");
            }

            ParentForm.Hide();

            string    url        = $"http://{textAddr.Text}:{textPort.Text}/";
            var       connection = new HubConnection(url);
            IHubProxy hubProxy   = connection.CreateHubProxy("GameHub");

            connection.Start().Wait();

            IListener udplistener = new WebSocketListener(hubProxy);
            ISender   udpsender   = new WebSocketSender(hubProxy);

            GameArea game = new GameArea(ParentForm, udplistener, udpsender);

            game.Show();
        }
Ejemplo n.º 17
0
        private void addButton_Click(object sender, EventArgs e)
        {
            var collection = database.GetCollection <BsonDocument>("posts");
            var post       = new BsonDocument
            {
                { "userId", User.id },
                { "title", "empty" },
                { "description", descriptionText.Text },
                { "date_created", DateTime.Today.ToString("dd/MM/yyyy") },
                { "time_created", DateTime.Now.ToString("HH:mm:ss tt") },
                { "posted_by", User.firstName + " " + User.lastName },
                { "likes", 0 },
                { "comments", 0 },
            };

            collection.InsertOne(post);
            Menu menu = new Menu();

            menu.Show();
            menu.OpenChildForm(new Newsfeed());
            ParentForm.Hide();
        }
        private void btnSignup_Click(object sender, EventArgs e)
        {
            if (!btnSignup.Enabled)
            {
                return;
            }

            if (!Do)
            {
                MetroFramework.MetroMessageBox.Show(this, "Error\nOpen settings by Control+Alt+Shift+A\n Then restart!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //MessageBox.Show(txtFullName.Text.Trim());
            if (txtFullName.isEmptyOrHint())
            {
                txtFullName.Focus();
                return;
            }

            if (txtEmail.isEmptyOrHint())
            {
                txtEmail.Focus();
                return;
            }
            if (txtUsername.isEmptyOrHint())
            {
                txtUsername.Focus();
                return;
            }

            if (txtPassword.isEmptyOrHint())
            {
                txtPassword.Focus();
                return;
            }

            btnSignup.Enabled   = false;
            lblLogin.Enabled    = false;
            txtUsername.Enabled = false;

            new Thread(() =>
            {
                bool isOkay = auth.Register(txtUsername.Text.Trim(), txtPassword.Text.Trim(), txtEmail.Text.Trim(),
                                            txtFullName.Text.Trim());

                if (isOkay)
                {
                    Thread mainThread = new Thread(() =>
                    {
                        MainWindow w = new MainWindow();
                        Application.Run(w);
                    })
                    {
                        Name = "Main"
                    };
                    mainThread.SetApartmentState(ApartmentState.STA);
                    mainThread.Start();
                    ParentForm?.Hide();
                }
                else
                {
                    MetroFramework.MetroMessageBox.Show(this, "Registered Failed!\nMaybe username or email already exist!", "Error", MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                    txtUsername.Enabled = true;
                    lblLogin.Enabled    = true;
                    btnSignup.Enabled   = true;
                }
            }).Start();
        }
Ejemplo n.º 19
0
        private void followButton_Click(object sender, EventArgs e)
        {
            var collection  = database.GetCollection <BsonDocument>("users");
            var builder     = Builders <BsonDocument> .Filter;
            var filter      = builder.Eq("_id", ObjectId.Parse(User.id));
            var filter2     = builder.Eq("_id", ObjectId.Parse(userId));
            var result2     = collection.Find(filter2).ToList();
            var friendList2 = result2[0]["friends"].AsBsonArray.Select(p => p.AsString).ToArray();


            if (followButton.Text == "Add Friend" || followButton.Text == "Accept Friend Request")
            {
                var update = Builders <BsonDocument> .Update.Push("friends", userId);

                var result = collection.UpdateOne(filter, update);
                User.friends.Add(userId);

                if (followButton.Text == "Accept Friend Request")
                {
                    User.friends2.Add(userId);
                }


                if (ParentForm.Text == "Notifications")
                {
                    ParentForm.ParentForm.Hide();
                    ParentForm.Hide();
                    Menu menu = new Menu();
                    menu.OpenChildForm(new Notifications());
                    menu.Show();
                }

                else
                {
                    SearchResult Srchresult = new SearchResult(result2[0][7].ToString());
                    ParentForm.Hide();
                    Srchresult.Show();
                    ParentForm.Update();
                }
            }
            else if (followButton.Text == "Friend Request Sent")
            {
                var update = Builders <BsonDocument> .Update.Pull("friends", userId);

                var          result     = collection.UpdateOne(filter, update);
                SearchResult Srchresult = new SearchResult(result2[0][7].ToString());
                this.Hide();
                User.friends.Remove(userId);
                ParentForm.Hide();
                Srchresult.Show();
            }
            else
            {
                var update = Builders <BsonDocument> .Update.Pull("friends", userId);

                var result = collection.UpdateOne(filter, update);
                User.friends.Remove(userId);
                var update2 = Builders <BsonDocument> .Update.Pull("friends", User.id);

                User.friends2.Remove(userId);
                var result3 = collection.UpdateOne(filter2, update2);
                if (ParentForm.Text == "Friends")
                {
                    ParentForm.ParentForm.Hide();
                    ParentForm.Hide();
                    Menu menu = new Menu();
                    menu.OpenChildForm(new Friends());
                    menu.Show();
                }
                else
                {
                    SearchResult Srchresult = new SearchResult(result2[0][7].ToString());
                    this.Hide();
                    ParentForm.Hide();
                    Srchresult.Show();
                }
            }
        }
Ejemplo n.º 20
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            bool   pass       = true;
            string dobText    = dobEdit.Value.ToString();
            var    collection = database.GetCollection <BsonDocument>("users");
            var    builder    = Builders <BsonDocument> .Filter;
            var    filter     = builder.Eq("email", emailLabel.Text);



            int i;

            // first name, last name, phone

            if (firstNameEdit.Text.Length == 0 || lastNameEdit.Text.Length == 0 || phoneEdit.Text.Length == 0)
            {
                MessageBox.Show("Please Fill All The Details");
                pass = false;
                reset();
            }
            else
            {
                for (i = 0; i < firstNameEdit.Text.Length; i++)
                {
                    if (!(firstNameEdit.Text[i] >= 65 && firstNameEdit.Text[i] <= 90 || firstNameEdit.Text[i] >= 97 && firstNameEdit.Text[i] <= 122))
                    {
                        MessageBox.Show("First Name Cannot Have Special Characters.");
                        pass = false;
                        reset();
                        break;
                    }
                }
                if (i == firstNameEdit.Text.Length)
                {
                    for (i = 0; i < lastNameEdit.Text.Length; i++)
                    {
                        if (!(lastNameEdit.Text[i] >= 65 && lastNameEdit.Text[i] <= 90 || lastNameEdit.Text[i] >= 97 && lastNameEdit.Text[i] <= 122))
                        {
                            MessageBox.Show("Last Name Cannot Have Special Characters.");
                            pass = false;
                            reset();
                            break;
                        }
                    }
                }
                if (i == lastNameEdit.Text.Length)
                {
                    if (phoneEdit.Text.Length == 11)
                    {
                        for (i = 0; i < phoneEdit.Text.Length; i++)
                        {
                            if (phoneEdit.Text[i] < 48 || phoneEdit.Text[i] > 57)
                            {
                                MessageBox.Show("Invalid Phone Number.");
                                pass = false;
                                reset();
                                break;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid Phone Number.");
                        pass = false;
                        reset();
                    }
                }
            }


            if (pass)
            {
                var update = Builders <BsonDocument> .Update.Set("firstName", firstNameEdit.Text).Set("lastName", lastNameEdit.Text).Set("gender", genderEdit.Text).Set("dob", dobEdit.Text).Set("phone", phoneEdit.Text).Set("relation", relationEdit.Text);

                var result  = collection.UpdateOne(filter, update);
                var result2 = collection.Find(filter).ToList();
                var user1   = result2[0];

                User.firstName  = user1[1].ToString();
                User.lastName   = user1[2].ToString();
                User.gender     = user1[3].ToString();
                User.dob        = user1[4].ToString();
                User.email      = user1[5].ToString();
                User.password   = user1[6].ToString();
                User.username   = user1[7].ToString();
                User.reputation = user1[8].ToInt32();
                User.phone      = user1[10].ToString();
                User.relation   = user1[11].ToString();
                this.Hide();
                ParentForm.Hide();
                Menu menu = new Menu();
                menu.OpenChildForm(new Bio());
                menu.Show();
            }
        }
Ejemplo n.º 21
0
 private void Bhide_Click(object sender, EventArgs e)
 {
     ParentForm.Hide();
 }
Ejemplo n.º 22
0
        private void AssignEvents()
        {
            comboBoxClientNum.SelectedIndexChanged += (sender, e) =>
            {
                if (!_checkSelected)
                {
                    return;
                }

                if (comboBoxClientNum.Items.Count > 0 && comboBoxClientNum.SelectedIndex >= 0)
                {
                    ClientInfo client = (ClientInfo)comboBoxClientNum.Items[comboBoxClientNum.SelectedIndex];
                    UOClientManager.AttachToClient(client.handle);
                }
            };

            customButtonRefreshClients.Click += (sender, e) => { ReloadClients(); };


            customButtonRebuildMaps.Click += (sender, e) =>
            {
                if (MessageBox.Show("All maps will be lost.\r\n\r\nAre you sure to continue?", "Attention!", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                ParentForm.Hide();
                MapsManager.RemoveMapsFiles();
                Global.MainWindow.RebuildMaps(true);
                Global.MainWindow.Show();
            };

            numericUpDownFPS.ValueChanged += (sender, e) =>
            {
                Global.SettingsCollection["fps"] = numericUpDownFPS.Value;
                Global.MainWindow.SetTimerIntervalByFps((int)numericUpDownFPS.Value);
            };

            radioButtonDetailed.CheckedChanged += (sender, e) =>
            {
                if (radioButtonDetailed.Checked)
                {
                    Global.SettingsCollection["mapkind"] = 0;
                    Global.Facet = Global.Facet;
                }
            };
            radioButtonNormal.CheckedChanged += (sender, e) =>
            {
                if (radioButtonNormal.Checked)
                {
                    Global.SettingsCollection["mapkind"] = 1;
                    Global.Facet = Global.Facet;
                }
            };
            customFlatButtonCheckNewVersion.Click += (sender, e) => { Core.Network.Update.CheckUpdates(); };

            radioButtonEnhanced.CheckedChanged += (sender, e) => { label3.Visible = textBoxClientPath.Visible = customButtonClientPath.Visible = radioButtonEnhanced.Checked; };

            customButtonClientPath.Click += (sender, e) =>
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog {
                    Description = "Select enhanced client folder"
                };
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Global.SettingsCollection["clientpath"] = Global.UOPath = textBoxClientPath.Text = dialog.SelectedPath;
                }
            };

            numericUpDownChatFontSize.ValueChanged += (sender, e) =>
            {
                Global.SettingsCollection["chatfontsize"] = (int)numericUpDownChatFontSize.Value;
                Global.MainWindow.ChatWindow?.ChangeFontSize();
            };
        }
Ejemplo n.º 23
0
        private void SignIn_bt_Click(object sender, EventArgs e)
        {
            if (usernametxt.Text == "" || passwordtxt.Text == "")
            {
                MessageBox.Show("Please enter all information", "Sign in error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (customerRadiobox.Checked == false && driverRadiobox.Checked == false && cookRadiobox.Checked == false && checkerRadiobox.Checked == false && adminRadiobox.Checked == false)
            {
                MessageBox.Show("Please enter all information", "Sign in error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                try
                {
                    username = usernametxt.Text;
                    user.con.Open();
                    if (user.con.State == System.Data.ConnectionState.Open) //to avoid database connection errors
                    {
                        string query = null;
                        if (sqlTable == "Admin")
                        {
                            query = "select top 1 * from " + sqlTable + " where Name = '" + usernametxt.Text + "' and Password = '******'";
                        }
                        else
                        {
                            query = "select top 1 * from " + sqlTable + " where Username = '******' and Password = '******'";
                        }
                        SqlCommand    cmd    = new SqlCommand(query, user.con);
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            MessageBox.Show("sign in successful", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ParentForm.Hide();
                            if (sqlTable == "Customer")
                            {
                                customerForm cf = new customerForm();
                                cf.Show();
                                customerUsername = usernametxt.Text;
                                //the customer's options goes here
                            }
                            else if (sqlTable == "Driver")
                            {
                                DriverUsername = usernametxt.Text;
                                driverForm df = new driverForm();
                                df.Show();

                                //the driver's options goes here
                            }
                            else if (sqlTable == "Cooks")
                            {
                                CookForm cf = new CookForm();
                                cf.Show();
                            }

                            else if (sqlTable == "Checker")
                            {
                                //Checker's options goes here
                                checker_username = usernametxt.Text;
                                checker_form ch = new checker_form();
                                ch.Show();
                            }
                            else if (sqlTable == "Admin")
                            {
                                //admin's options goes here
                                Admin_form af = new Admin_form();
                                af.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("please enter username and password again", "username or password incorrect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can not open connection to database", "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.ToString(), "Data connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    user.con.Close();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Consumer method that processes mouse events in <see cref="MouseEvents" /> that are recorded by <see cref="MouseHookCallback" />
        /// </summary>
        protected void InterpretMouseEvents()
        {
            foreach (MouseEvent mouseEvent in MouseEvents.GetConsumingEnumerable())
            {
                int            nCode      = mouseEvent.nCode;
                IntPtr         wParam     = mouseEvent.wParam;
                MSLLHOOKSTRUCT?hookStruct = mouseEvent.MouseData;
                if (nCode >= 0 && (int)WM.WM_MOUSEMOVE == (int)wParam)
                {
                    Point cursorPosition = new Point(hookStruct.Value.pt.x, hookStruct.Value.pt.y);
                    bool  reRender       = false;
                    if (s_tornTab != null && DropAreas != null)
                    {
                        for (int i = 0; i < DropAreas.Length; i++)
                        {
                            if (DropAreas[i].Item2.Contains(cursorPosition)) // If the cursor is within the drop area, combine the tab for the window that belongs to that drop area
                            {
                                TitleBarTab tabToCombine = null;
                                lock (s_tornTabLock)
                                {
                                    if (s_tornTab != null)
                                    {
                                        tabToCombine = s_tornTab;
                                        s_tornTab    = null;
                                    }
                                }

                                if (tabToCombine != null)
                                {
                                    int i1 = i;
                                    Invoke(new Action(() =>
                                    {
                                        DropAreas[i1].Item1.TabRenderer.CombineTab(tabToCombine, cursorPosition);
                                        tabToCombine = null;
                                        s_tornTabForm.Close();
                                        s_tornTabForm = null;
                                        if (ParentForm.Tabs.Count == 0)
                                        {
                                            ParentForm.Close();
                                        }
                                    }));
                                }
                            }
                        }
                    }
                    else if (!ParentForm.TabRenderer.IsTabRepositioning)
                    {
                        // If we were over a close button previously, check to see if the cursor is still over that tab's close button; if not, re-render
                        if (IsOverCLoseButtonForTab != -1 && (IsOverCLoseButtonForTab >= ParentForm.Tabs.Count || !ParentForm.TabRenderer.IsOverCloseButton(ParentForm.Tabs[IsOverCLoseButtonForTab], GetRelativeCursorPosition(cursorPosition))))
                        {
                            reRender = true;
                            IsOverCLoseButtonForTab = -1;
                        }
                        else // Otherwise, see if any tabs' close button is being hovered over
                        {
                            for (int i = 0; i < ParentForm.Tabs.Count; i++)
                            {
                                if (ParentForm.TabRenderer.IsOverCloseButton(ParentForm.Tabs[i], GetRelativeCursorPosition(cursorPosition)))
                                {
                                    IsOverCLoseButtonForTab = i;
                                    reRender = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Invoke(new Action(() =>
                        {
                            s_wasDragging      = true;
                            Rectangle dragArea = TabDropArea;
                            dragArea.Inflate(ParentForm.TabRenderer.TabTearDragDistance, ParentForm.TabRenderer.TabTearDragDistance);
                            if (!dragArea.Contains(cursorPosition) && s_tornTab == null)
                            {
                                lock (s_tornTabLock)
                                {
                                    if (s_tornTab == null)
                                    {
                                        ParentForm.TabRenderer.IsTabRepositioning = false;
                                        s_tornTab = ParentForm.SelectedTab;
                                        s_tornTab.ClearEventSubscriptions();
                                        s_tornTabForm = new TornTabForm(s_tornTab, ParentForm.TabRenderer);
                                    }
                                }

                                if (s_tornTab != null)
                                {
                                    ParentForm.SelectedTabIndex = ParentForm.SelectedTabIndex == ParentForm.Tabs.Count - 1 ? ParentForm.SelectedTabIndex - 1 : ParentForm.SelectedTabIndex + 1;
                                    ParentForm.Tabs.Remove(s_tornTab);
                                    if (ParentForm.Tabs.Count == 0)
                                    {
                                        ParentForm.Hide();
                                    }
                                    s_tornTabForm.Show();
                                    DropAreas = (from window in ParentForm.ApplicationContext.OpenWindows.Where(w => w.Tabs.Count > 0) select new Tuple <TitleBarTabs, Rectangle>(window, window.TabDropArea)).ToArray();
                                }
                            }
                        }));
                    }
                    Invoke(new Action(() => OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, cursorPosition.X, cursorPosition.Y, 0))));
                    if (ParentForm.TabRenderer.IsTabRepositioning)
                    {
                        reRender = true;
                    }
                    if (reRender)
                    {
                        Invoke(new Action(() => Render(cursorPosition, true)));
                    }
                }
                else if (nCode >= 0 && (int)WM.WM_LBUTTONDOWN == (int)wParam)
                {
                    s_wasDragging = false;
                }
                else if (nCode >= 0 && (int)WM.WM_LBUTTONUP == (int)wParam)
                {
                    if (s_tornTab != null)
                    {
                        TitleBarTab tabToRelease = null;
                        lock (s_tornTabLock)
                        {
                            if (s_tornTab != null)
                            {
                                tabToRelease = s_tornTab;
                                s_tornTab    = null;
                            }
                        }

                        if (tabToRelease != null)
                        {
                            Invoke(new Action(() =>
                            {
                                TitleBarTabs newWindow = (TitleBarTabs)Activator.CreateInstance(ParentForm.GetType());
                                if (newWindow.WindowState == FormWindowState.Maximized)
                                {
                                    Screen screen           = Screen.AllScreens.First(s => s.WorkingArea.Contains(Cursor.Position));
                                    newWindow.StartPosition = FormStartPosition.Manual;
                                    newWindow.WindowState   = FormWindowState.Normal;
                                    newWindow.Left          = screen.WorkingArea.Left;
                                    newWindow.Top           = screen.WorkingArea.Top;
                                    newWindow.Width         = screen.WorkingArea.Width;
                                    newWindow.Height        = screen.WorkingArea.Height;
                                }
                                else
                                {
                                    newWindow.Left = Cursor.Position.X;
                                    newWindow.Top  = Cursor.Position.Y;
                                }
                                tabToRelease.Parent = newWindow;
                                ParentForm.ApplicationContext.OpenWindow(newWindow);
                                newWindow.Show();
                                newWindow.Tabs.Add(tabToRelease);
                                newWindow.SelectedTabIndex = 0;
                                newWindow.ResizeTabContents();
                                s_tornTabForm.Close();
                                s_tornTabForm = null;
                                if (ParentForm.Tabs.Count == 0)
                                {
                                    ParentForm.Close();
                                }
                            }));
                        }
                    }
                    Invoke(new Action(() => OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0))));
                }
            }
        }