Exemplo n.º 1
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            Names_Label.Text       = Names_Label.Text.Replace("Nick_1", ChatClient.thisNick).Replace("Color_1", ChatClient.thisColour).Replace("Nick_2", ChatClient.enemyNick).Replace("Color_2", ChatClient.enemyColour);
            Chat_TextBox.ForeColor = Color.Black;
            WriteInColour(Color.CadetBlue, $"{ChatClient.thisNick}: Hi\n", 0, ChatClient.thisNick.Length);
            WriteInColour(Color.MediumVioletRed, $"{ChatClient.enemyNick}: Hello\n", 0, ChatClient.enemyNick.Length);
            await Task.Run(() => ChatClient.StartReading());

            await Task.Run(() => {
                while (true)
                {
                    if (ChatClient.read_strings.Count > 0)
                    {
                        lock (ChatClient.read_strings)
                        {
                            var tuple = ChatClient.read_strings.Dequeue();
                            if (tuple.Item1 == true)
                            {
                                WriteInColour(Color.MediumVioletRed, $"{ChatClient.enemyNick}: {tuple.Item2}\n", 0, ChatClient.enemyNick.Length);
                            }
                            else
                            {
                                Chat_TextBox.AppendText($"{tuple.Item2}\n");
                            }
                        }
                    }
                    System.Threading.Thread.Sleep(350);
                }
            });
        }
Exemplo n.º 2
0
 private void WriteInColour(Color c, string s, int start, int length)
 {
     Chat_TextBox.SelectionStart  = Chat_TextBox.Text.Length;
     Chat_TextBox.SelectionLength = length;
     Chat_TextBox.SelectionColor  = c;
     Chat_TextBox.AppendText(s.Substring(start, length));
     Chat_TextBox.SelectionColor = Color.Black;
     Chat_TextBox.AppendText(s.Substring(length));
 }