public void EnableControls(GroupBox gbPortSettings, GroupBox gbLineSettings, CheckBox chkDTR, CheckBox chkRTS, TextBox txtSendData, Button btnSend, Button btnRequestPicture, Button btnOpenPort, Button btnAtachFile, bool portOpen, GroundStation gs, DataMode currentDataMode)
        {
            // Enable/disable controls based on whether the port is open or not
            System.Diagnostics.Debug.Print("Enable controls TP: " + !portOpen);
            gbPortSettings.Invoke(new EventHandler(delegate
            {
                gbPortSettings.Enabled    = !portOpen;
                btnRequestPicture.Enabled = txtSendData.Enabled = btnSend.Enabled = portOpen;

                if (portOpen && (currentDataMode == DataMode.Image || currentDataMode == DataMode.TextFile))
                {
                    btnAtachFile.Enabled = true;
                }
                else
                {
                    btnAtachFile.Enabled = false;
                }
                if (portOpen)
                {
                    btnOpenPort.Text = "&Close Port";
                }
                else
                {
                    btnOpenPort.Text = "&Open Port";
                }
                gs.ConnectionChanged(portOpen);
            }));

            gbLineSettings.Invoke(new EventHandler(delegate
            {
                chkDTR.Enabled = !portOpen;
                chkRTS.Enabled = !portOpen;
            }));
        }
Exemple #2
0
        public void Game()
        {
            while (true)
            {
                Application.DoEvents();
                if (playerInfo.nt.DataAvailable)
                {
                    string x = playerInfo.br.ReadString();

                    string[] recievedString = x.Split('_');
                    switch (recievedString[0])
                    {
                    case "right":
                        string[] recievedIndex = recievedString[2].Split(',');
                        for (int i = 0; i < recievedIndex.Length; i++)
                        {
                            word_labels[int.Parse(recievedIndex[i])].Text = word[int.Parse(recievedIndex[i])].ToString();
                            word_without_space--;
                        }
                        word_without_space = int.Parse(recievedString[3]);
                        log.Text           = recievedString[4] + " pressed " + recievedString[1];
                        if (recievedString[4] == playerInfo.player1)
                        {
                            Stat1lbl.Text      = "Playing...";
                            Stat1lbl.BackColor = Color.Red;
                            Stat2lbl.Text      = "Waiting...";
                            Stat2lbl.BackColor = Color.Bisque;
                        }
                        else if (recievedString[4] == playerInfo.player2)
                        {
                            Stat2lbl.Text      = "Playing...";
                            Stat2lbl.BackColor = Color.Red;
                            Stat1lbl.Text      = "Waiting...";
                            Stat1lbl.BackColor = Color.Bisque;
                        }
                        if (word_without_space == 0)
                        {
                            MessageBox.Show(recievedString[4] + " Is the winner");
                        }
                        break;


                    case "newWord":
                        word = recievedString[1];
                        this.Controls.Remove(labelsGroup);
                        playerInfo.word = word;
                        word_label.Text = word;
                        labelsGroup.Invoke((MethodInvoker) delegate
                        {
                            drawWord();
                        });


                        break;
                    }
                }
            }
        }
Exemple #3
0
        public void ApplyConfig()
        {
            if (control.InvokeRequired)
            {
                control.Invoke((Action)(() => ApplyConfig()));
                return;
            }

            chkEnabled.Checked = plugin.Config.Enabled;
        }
Exemple #4
0
 public void EnableGroup(GroupBox grupo, bool status)
 {
     if (groupBox1.InvokeRequired)
     {
         grupo.Invoke(new EnableGrupo(EnableGroup), grupo, status);
     }
     else
     {
         grupo.Enabled = status;
     }
 }
Exemple #5
0
 private void SetGroupBoxText(GroupBox groupbox, string str)
 {
     if (groupbox.InvokeRequired)
     {
         SetGroupBoxTextDelegate d = new SetGroupBoxTextDelegate(SetGroupBoxText);
         groupbox.Invoke(d, new object[] { groupbox, str });
     }
     else
     {
         groupbox.Text = str;
     }
 }
Exemple #6
0
 public void TextGroupBox(string text)
 {
     if (_grp != null)
     {
         if (_grp.InvokeRequired)
         {
             delegateTextLabel deleg = new delegateTextLabel(TextGroupBox);
             _grp.Invoke(deleg, new object[] { text });
         }
         else
         {
             _grp.Text = text;
         }
     }
 }
Exemple #7
0
        public static void SetEnableState(GroupBox gb, bool enabled)
        {
            MethodInvoker mi = delegate
            {
                gb.Enabled = enabled;
            };

            if (gb.InvokeRequired)
            {
                gb.Invoke(mi);
            }
            else
            {
                mi();
            }
        }
Exemple #8
0
        public void Game()
        {
            while (true)
            {
                Application.DoEvents();
                if (playerInfo.nt.DataAvailable)
                {
                    string x = playerInfo.br.ReadString();

                    string [] recievedString = x.Split('_');

                    switch (recievedString[0])

                    {
                    case "Request":
                        string       player2Name = recievedString[1];
                        DialogResult dr          = MessageBox.Show(player2Name + " wants to join you...", " Request", MessageBoxButtons.YesNo);
                        if (dr == DialogResult.Yes)
                        {
                            pl2.Text = player2Name;
                            playerInfo.bw.Write("RequestYes" + "_" + playerInfo.playerName);
                            if (playerInfo.owner)
                            {
                                groupBox1.Enabled = true;
                            }
                        }
                        else
                        {
                            playerInfo.bw.Write("RequestNon");
                        }
                        break;

                    case "right":
                        string[] recievedIndex = recievedString[2].Split(',');
                        for (int i = 0; i < recievedIndex.Length; i++)
                        {
                            word_labels[int.Parse(recievedIndex[i])].Text = word[int.Parse(recievedIndex[i])].ToString();
                        }
                        letters[recievedString[1].ToUpper().ToCharArray()[0]].Enabled = false;
                        if (groupBox1.Enabled == true)
                        {
                            groupBox1.Enabled = false;
                        }
                        break;

                    case "wrong":

                        if (groupBox1.Enabled == false)
                        {
                            groupBox1.Enabled = true;
                        }
                        letters[recievedString[1].ToUpper().ToCharArray()[0]].Enabled = false;

                        break;

                    case "newWord":
                        if (recievedString.Length > 2)
                        {
                            if (recievedString[2] == "switch")
                            {
                                pl1.Text         = playerInfo.playerName;
                                pl2.Text         = "Waiting";
                                playerInfo.owner = true;
                            }
                            if (recievedString[2] == "opponentLeft")
                            {
                                pl2.Text = "Waiting";
                            }
                        }

                        word = recievedString[1];
                        this.Controls.Remove(labelsGroup);
                        playerInfo.word = word;
                        //word_label.Text = word;
                        labelsGroup.Invoke((MethodInvoker) delegate
                        {
                            drawWord();
                        });
                        groupBox1.Invoke((MethodInvoker) delegate
                        {
                            foreach (var item in letters.Values)
                            {
                                item.Enabled = true;
                            }
                        });
                        break;

                    case "closeP2":
                        playerInfo.owner = false;
                        Thread Wth = new Thread(() =>
                        {
                            Application.Run(new Form1());
                        });
                        Wth.SetApartmentState(ApartmentState.STA);
                        Wth.Start();
                        Application.Exit();
                        break;
                    }

                    if (recievedString.Length > 3)
                    {
                        word_without_space = int.Parse(recievedString[3]);

                        if (word_without_space == 0)
                        {
                            DialogResult dr = MessageBox.Show("loser do you want to play again?", " Request", MessageBoxButtons.YesNo);
                            if (dr == DialogResult.Yes)
                            {
                                foreach (var item in word_labels)
                                {
                                    this.Controls.Remove(item);
                                }
                                playerInfo.bw.Write("acceptNewGame" + "_" + playerInfo.score);
                            }
                            else
                            {
                                playerInfo.bw.Write("RejectNewGame" + "_" + playerInfo.score);
                            }
                        }
                    }
                }
            }
        }
Exemple #9
0
 public void takeTheThreadFlag(GroupBox GB_stX, Boolean state)
 {
     GB_stX.Invoke((MethodInvoker)(() =>
                                   GB_stX.Enabled = state));
 }