All pastes #945280 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-03-16 20:35 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Threading;
using System.Text.RegularExpressions;

using BoogieBot.Common;


namespace BoogieBot.GUIApp
{
    class ChatTab : System.Windows.Forms.TabPage 
    {

        private RichTextBox output;
        private TextBox input;
        private Button send;
        private Button close;
        public String name;
        private ChatMsg type;


        public ChatTab(ChatMsg type, string sender )
        {

            this.output = new RichTextBox() ;
            this.input = new TextBox();
            this.send = new Button();
            this.close = new Button();
            
            this.output.Name = "output";
            this.output.Size = new System.Drawing.Size(630, 290);
            this.output.Location = new Point(0, 0);
            this.output.ReadOnly = true;

            this.input.Name = "input";
            this.input.Size = new System.Drawing.Size(460, 20);
            this.input.Location = new Point(10, 300);

            this.send.Name = "send";
            this.send.Size = new System.Drawing.Size(70,21);
            this.send.Location = new Point(480, 300);
            this.send.Text = "Send";

            this.close.Name = "close";
            this.close.Size = new System.Drawing.Size(70, 21);
            this.close.Location = new Point(560, 300);
            this.close.Text = "Close";



            switch (type)
            {
                case ChatMsg.CHAT_MSG_SAY:
                case ChatMsg.CHAT_MSG_YELL:
                    this.Text = "! Main";
                    this.Controls.Add(output);
                    this.Controls.Add(input);
                    this.send.Enabled = false;
                    this.Controls.Add(send);
                    this.close.Enabled = false;
                    this.Controls.Add(close);
                    break;
                case ChatMsg.CHAT_MSG_WHISPER:
                    this.Text = "! Whispers - " + sender;
                    this.name = sender;
                    this.Controls.Add(output);
                    this.Controls.Add(input);
                    this.Controls.Add(send);
                    this.Controls.Add(close);
                    break;
                case ChatMsg.CHAT_MSG_CHANNEL:
                    this.Text = "! Channel - " + sender;
                    this.name = sender;
                    this.Controls.Add(output);
                    this.Controls.Add(input);
                    this.Controls.Add(send);
                    this.Controls.Add(close);
                    break;
                case ChatMsg.CHAT_MSG_SYSTEM:
                    this.Text = "! System";
                    this.Controls.Add(send);
                    this.close.Enabled = false;
                    this.Controls.Add(close);
                    break;
             }

            this.Controls.Add(output);
            this.Controls.Add(input);
            this.Controls.Add(send);
            this.Controls.Add(close);

            this.Enter += new EventHandler(ChatTab_GotFocus);

            this.type = type;
        }

        void ChatTab_GotFocus(object sender, EventArgs e)
        {
            switch (type)
            {

                case ChatMsg.CHAT_MSG_SAY:
                case ChatMsg.CHAT_MSG_YELL:
                    this.Text = "Main";
                    break;
                case ChatMsg.CHAT_MSG_WHISPER:
                    this.Text = "Whispers - " + name;
                    break;
                case ChatMsg.CHAT_MSG_CHANNEL:
                    this.Text = "Channel - " + name;
                    break;
                case ChatMsg.CHAT_MSG_SYSTEM:
                    this.Text = "System";
                    break;
            }
        }

        public void AddText(string text)
        {
            text = CleanText(text);
            this.output.Text += text;

            switch (type)
            {

                case ChatMsg.CHAT_MSG_SAY:
                case ChatMsg.CHAT_MSG_YELL:
                    this.Text = "! Main";
                    break;
                case ChatMsg.CHAT_MSG_WHISPER:
                    this.Text = "! Whispers - " + name;
                    break;
                case ChatMsg.CHAT_MSG_CHANNEL:
                    this.Text = "! Channel - " + name;
                    break;
                case ChatMsg.CHAT_MSG_SYSTEM:
                    this.Text = "! System";
                    break;
            }
        }

        public string CleanText(string text)
        {
            string reg = @"[|][a-zA-Z][0-9a-fA-F]{0,8}";
            Regex regexp = new Regex(reg);

            string output = regexp.Replace(text, "");

            return output;
        }


   }
}