public TextColoringPanel(SendBox currentSendbox)
        {
            timedUpdate.Interval = 50; //timer tick to add micro delay to ChatBox preview update.
            timedUpdate.Tick    += timedUpdate_Tick;
            InitializeComponent();
            Icon = ZklResources.ZkIcon;
            button1.BackColor  = TextColor.GetColor(0);  //white
            button2.BackColor  = TextColor.GetColor(1);  //black
            button3.BackColor  = TextColor.GetColor(2);  //blue
            button4.BackColor  = TextColor.GetColor(3);  //green
            button5.BackColor  = TextColor.GetColor(4);  //red
            button6.BackColor  = TextColor.GetColor(5);  //brown
            button7.BackColor  = TextColor.GetColor(6);  //purple
            button8.BackColor  = TextColor.GetColor(7);  //orange
            button9.BackColor  = TextColor.GetColor(8);  //yellow
            button10.BackColor = TextColor.GetColor(9);  //light green
            button11.BackColor = TextColor.GetColor(10); //teal
            button12.BackColor = TextColor.GetColor(11);
            button13.BackColor = TextColor.GetColor(12);
            button14.BackColor = TextColor.GetColor(13);
            button15.BackColor = TextColor.GetColor(14);
            button16.BackColor = TextColor.GetColor(15);
            if (sendBox.TextBox.SelectionLength <= 1)
            {
                sendBox.TextBox.SelectionStart = 0;
            }
            comboBox1.SelectedItem   = "To-line-end";
            ignoreSpaceCheck.Checked = true;

            sendBox.dontSendTextOnEnter     = true; //pressing enter wont send text
            sendBox.TextBox.ScrollBars      = ScrollBars.Vertical;
            sendBox.dontUseUpDownHistoryKey = true;
            sendBox.CompleteWord           += (word) => //autocomplete of username
            {
                var w = word.ToLower();
                IEnumerable <string> firstResult = new string[1];
                ChatControl          zkChatArea  = Program.MainWindow.navigationControl.ChatTab.GetChannelControl("zk");
                if (zkChatArea != null)
                {
                    IEnumerable <string> extraResult = zkChatArea.playerBox.GetUserNames()
                                                       .Where(x => x.ToLower().StartsWith(w))
                                                       .Union(zkChatArea.playerBox.GetUserNames().Where(x => x.ToLower().Contains(w)));
                    firstResult = firstResult.Concat(extraResult);
                }
                return(firstResult);
            };
            sendBox.TextBox.WordWrap = true;
            sendBox.Text             = currentSendbox.Text; //copy paste from chat area to coloring panel
            currentSendbox_          = currentSendbox;
            Program.ToolTip.SetText(sendBox, "Tips: press CTRL+R/G/B on chatbox for instant Red,Green or Blue coloring");
        }
        private void ColorButtonClicked(object sender, EventArgs e)
        {
            int buttonNum = int.Parse((sender as Button).Name.Substring(6)) - 1; //convert string to number

            if (waitForBackground)
            {
                helpLabel.Text            = "";
                backgroundcolor.Text      = "";
                backgroundcolor.BackColor = TextColor.GetColor(buttonNum);
                waitForBackground         = false; //background color selected, toggle off background color mode
                backgroundColor           = buttonNum;
                return;
            }
            int selectionStart = sendBox.TextBox.SelectionStart;

            if (sendBox.Text.Length > 0 && selectionStart < sendBox.Text.Length) //is not at string end
            {
                helpLabel.Text = "";
                if (sendBox.SelectionLength >= 1)
                {
                    sendBox.Text           = sendBox.Text.Insert(selectionStart + sendBox.SelectionLength, "\x03");
                    sendBox.Text           = sendBox.Text.Insert(selectionStart, "\x03" + buttonNum.ToString("00") + "," + backgroundColor.ToString("00")); //convert number to string
                    sendBox.SelectionStart = selectionStart + 6;
                }
                else if (progressType == 1)
                {
                    if (ignoreSpaceCheck.Checked)
                    {
                        ColorWholeLine(buttonNum);
                    }
                    else
                    {
                        while (ColorWords(buttonNum))
                        {
                            ;
                        }
                    }
                }
                else if (progressType == 2)
                {
                    ColorWords(buttonNum);
                }
                else if (progressType == 3) //"Char-by-char"
                {
                    int newLineChar = IsAtNewLine(selectionStart);
                    int textLen     = sendBox.Text.Length;
                    while (selectionStart < textLen && newLineChar > -1) //skip over current line-end
                    {
                        selectionStart = selectionStart + newLineChar;
                        newLineChar    = IsAtNewLine(selectionStart);
                    }
                    if (ignoreSpaceCheck.Checked)
                    {
                        string tempSubstring = sendBox.Text.Substring(selectionStart, 1);
                        while (selectionStart < textLen && (tempSubstring == " " || tempSubstring == "\t")) //skip over space
                        {
                            selectionStart = selectionStart + 1;
                            if (selectionStart < textLen)
                            {
                                tempSubstring = sendBox.Text.Substring(selectionStart, 1);
                            }
                        }
                    }
                    if (selectionStart < textLen)
                    {
                        sendBox.Text = sendBox.Text.Insert(selectionStart + 1, "\x03");
                    }
                    else
                    {
                        sendBox.Text = sendBox.Text + "\x03";  //end of string
                    }
                    sendBox.Text           = sendBox.Text.Insert(selectionStart, "\x03" + buttonNum.ToString("00") + "," + backgroundColor.ToString("00"));
                    sendBox.SelectionStart = selectionStart + 8;
                }
            }
            else
            {
                helpLabel.Text = "Do: check caret position/selection";
            }
        }