private void button17_Click(object sender, EventArgs e) //remove color button
 {
     sendBox.TextBox.SelectionStart = 0;
     sendBox.Text   = TextColor.StripAllCodes(sendBox.Text);
     helpLabel.Text = "";
 }
        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";
            }
        }