Hi,
Hyperlink inlines inherit from
NInputElement, so you can subscribe to any mouse or keyboard event exposed by this class. The following piece of code demonstrates how to create a rich text document that contains a hyperlink, which opens a message box when clicked:
private NDocumentBlock CreateTextDocument()
{
NDocumentBlock document = new NDocumentBlock();
// Create a paragraph
NParagraph paragraph = new NParagraph();
paragraph.Inlines.Add(new NTextInline("The following is a hyperlink that shows a message box when clicked:"));
paragraph.Inlines.Add(new NLineBreakInline());
// Add a hyperlink inline and subscribe to its MouseDown event
NHyperlinkInline hyperlinkInline = new NHyperlinkInline("Click me to show a message box");
hyperlinkInline.MouseDown += OnHyperlinkInlineMouseDown;
paragraph.Inlines.Add(hyperlinkInline);
// Create a section and add the paragraph to it
NSection section = new NSection();
section.Blocks.Add(paragraph);
document.Sections.Add(section);
return document;
}
private void OnHyperlinkInlineMouseDown(NMouseButtonEventArgs arg)
{
if (arg.Button == ENMouseButtons.Left && !arg.Cancel)
{
// Show a message box
NMessageBox.Show("Hyperlink clicked", "Message");
// Mark the event as handled
arg.Cancel = true;
}
}
You can then assign the created document block to the
Content property of an
NRichTextView instance.
Best Regards,
Nevron Support Team