Пример #1
0
        void treeViewContent_AfterSelect(object sender, TreeViewEventArgs e)
        {
            richTextBoxContent.Clear();

            if (e.Node.Tag == null || !(e.Node.Tag is Content))
            {
                return;
            }

            var link = new Native.CharFormat2
            {
                Size    = Marshal.SizeOf(typeof(Native.CharFormat2)),
                Mask    = Native.CfmLink,
                Effects = Native.CfmLink,
            };

            Trace.TraceInformation("Updating richTextBoxContent with content {0}", e.Node.Tag as Content);
            richTextBoxContent.Text = ContentInfo.GetText(e.Node.Tag as Content);
            var boldFont = new Font(richTextBoxContent.Font, FontStyle.Bold);
            var start    = 0;

            while (richTextBoxContent.Find(":\t", start, RichTextBoxFinds.None) >= 0)
            {
                var endPos   = richTextBoxContent.Find(":\t", start, RichTextBoxFinds.None);
                var line     = richTextBoxContent.GetLineFromCharIndex(endPos);
                var startPos = richTextBoxContent.GetFirstCharIndexFromLine(line);
                if (startPos <= start && start > 0)
                {
                    startPos = start + 1;
                }
                richTextBoxContent.Select(startPos, endPos - startPos + 1);
                if (richTextBoxContent.SelectedText.IndexOf("\t") == -1)
                {
                    richTextBoxContent.SelectionFont = boldFont;
                }
                start = endPos + 1;
            }
            var linkMatch = ContentLink.Match(richTextBoxContent.Text);

            while (linkMatch.Success)
            {
                richTextBoxContent.Select(linkMatch.Index, linkMatch.Length);
                richTextBoxContent.SelectedRtf = String.Format(@"{{\rtf{{{0}{{\v{{\u1.{0}\u1.{1}}}\v0}}}}}}", linkMatch.Groups[1].Value, linkMatch.Groups[2].Value);
                richTextBoxContent.Select(linkMatch.Index, linkMatch.Groups[1].Value.Length * 2 + linkMatch.Groups[2].Value.Length + 2);
                Native.SendMessage(richTextBoxContent.Handle, Native.EmSetCharFormat, Native.ScfSelection, ref link);
                linkMatch = ContentLink.Match(richTextBoxContent.Text);
            }
            richTextBoxContent.Select(0, 0);
            richTextBoxContent.SelectionFont = richTextBoxContent.Font;
        }
        void treeViewContent_AfterSelect(object sender, TreeViewEventArgs e)
        {
            richTextBoxContent.Clear();

            if (e.Node.Tag == null || !(e.Node.Tag is Content))
            {
                return;
            }

            var link = new Native.CharFormat2
            {
                Size    = Marshal.SizeOf(typeof(Native.CharFormat2)),
                Mask    = Native.CfmLink,
                Effects = Native.CfmLink,
            };

            Trace.TraceInformation("Updating richTextBoxContent with content {0}", e.Node.Tag as Content);
            richTextBoxContent.Text = ContentInfo.GetText(e.Node.Tag as Content);
            var boldFont  = new Font(richTextBoxContent.Font, FontStyle.Bold);
            var boldMatch = ContentBold.Match(richTextBoxContent.Text);

            while (boldMatch.Success)
            {
                richTextBoxContent.Select(boldMatch.Groups[1].Index, boldMatch.Groups[1].Length);
                richTextBoxContent.SelectionFont = boldFont;
                boldMatch = ContentBold.Match(richTextBoxContent.Text, boldMatch.Groups[1].Index + boldMatch.Groups[1].Length);
            }
            var linkMatch = ContentLink.Match(richTextBoxContent.Text);

            while (linkMatch.Success)
            {
                richTextBoxContent.Select(linkMatch.Index, linkMatch.Length);
                richTextBoxContent.SelectedRtf = String.Format(@"{{\rtf{{{0}{{\v{{\u1.{0}\u1.{1}}}\v0}}}}}}", linkMatch.Groups[1].Value, linkMatch.Groups[2].Value);
                richTextBoxContent.Select(linkMatch.Index, linkMatch.Groups[1].Value.Length * 2 + linkMatch.Groups[2].Value.Length + 2);
                Native.SendMessage(richTextBoxContent.Handle, Native.EmSetCharFormat, Native.ScfSelection, ref link);
                linkMatch = ContentLink.Match(richTextBoxContent.Text);
            }
            richTextBoxContent.Select(0, 0);
            richTextBoxContent.SelectionFont = richTextBoxContent.Font;
        }