public static String bbCodeToRtf(String bbCodeText, RichTextBox texbox)
        {
            _init();

            bbCodeParser.input = bbCodeText;
            BBCodeUtils.applyStyleTreeToTextbox(texbox, bbCodeParser.input, bbCodeParser.parse());

            return(texbox.Rtf);
        }
        public static void applyStyleTreeToTextbox(RichTextBox tf, String input, IndexTree bbCodeTree)
        {
            if (tf == null || bbCodeTree == null || input == null || input.Length < 1)
            {
                return;
            }

            tf.Text = "";

            BBCodeStyle rootStyle = new BBCodeStyle();

            rootStyle.isAbsFontSize = false;
            rootStyle.fontName      = tf.Font.Name;
            rootStyle.fontSize      = tf.Font.Size;
            rootStyle.isAbsFontSize = true;
            rootStyle.foreColor     = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
            rootStyle.backColor     = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionBackColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
            rootStyle.isBold        = tf.Font.Bold ? StateMode.ON : StateMode.OFF;
            rootStyle.isItalic      = tf.Font.Italic ? StateMode.ON : StateMode.OFF;
            rootStyle.isStriked     = tf.Font.Strikeout ? StateMode.ON : StateMode.OFF;
            rootStyle.isUnderlined  = tf.Font.Underline ? StateMode.ON : StateMode.OFF;

            PairTag rootPair = new PairTag(new BBCodeTagMatch(true, 0, "", "", "", 0, 0, false), new VoidCloserTagMatch(input.Length));

            (rootPair.openerMatch as BBCodeTagMatch).bbCodeStyle = rootStyle;

            bbCodeTree      = IndexTree.cloneTree(bbCodeTree);
            bbCodeTree.data = rootPair;

            List <IndexTree> flatTree     = IndexTree.flattenTree(bbCodeTree);
            String           flatText     = BBCodeUtils.assembleOutput(input, bbCodeTree);
            String           corrFlatText = _replaceEnclosures(flatText);

            IndexTree.normalizeTree(bbCodeTree);
            flatTree = IndexTree.flattenTree(bbCodeTree);

            tf.Text = corrFlatText /*flatText*/;

            if (flatText == input)
            {
                return;
            }

            String currText;
            String currCorrText;
            int    offsetA = 0;
            int    offsetB = 0;
            int    idxA, idxB;
            int    i = -1;
            int    l = flatTree.Count;

            while (++i < l)
            {
                idxA = flatTree[i].indexA;
                idxB = flatTree[i].indexB;

                currText     = flatText.Substring(idxA, idxB - idxA);
                currCorrText = _replaceEnclosures(currText);

                offsetB = currCorrText.Length + idxA - idxB;

                applyStyleToTextbox(BBCodeUtils.getCascadedNodeStyle(flatTree[i]),
                                    tf,
                                    idxA + offsetA,
                                    idxB + offsetA + offsetB);

                offsetA += offsetB;
            }

            tf.Select(tf.Text.Length, tf.Text.Length);
        }