示例#1
0
        private void SendToLink(RichTextBox box, int index)
        {
            if (box.SelectionColor != LinkColor)
            {
                return;
            }
            var linkfont = new Font(box.SelectionFont, FontStyle.Underline);

            if (!Resolve.EqualFonts(box.SelectionFont, linkfont))
            {
                return;
            }

            int selectionstart = index;
            int selectionend   = index;

            for (int c = index - 1; c >= 0; --c)
            {
                box.SelectionStart = c;
                if (!Resolve.EqualFonts(box.SelectionFont, linkfont) || box.SelectionColor != LinkColor)
                {
                    selectionstart = c;
                    break;
                }
                if (c == 0)
                {
                    selectionstart = 0;
                }
            }
            for (int c = index + 1; c < box.Text.Length; ++c)
            {
                box.SelectionStart = c;
                if (!Resolve.EqualFonts(box.SelectionFont, linkfont) || box.SelectionColor != LinkColor)
                {
                    selectionend = c - 1;
                    break;
                }
            }
            box.SelectionStart = index;
            if (selectionstart == selectionend)
            {
                return;
            }
            var key = box.Text.Substring(selectionstart, selectionend - selectionstart);

            key = ScriptX.RemoveNewLines(key);
            if (!_linkmap.TryGetValue(key, out string result))
            {
                return;
            }
            var e = new LinkClickedEventArgs(result);

            RichTextBox_LinkClickedEvent(box, e);
        }