Anoop Kovoor
Posts: 19
Joined: 2012-11-06
|
Hi,
I'm using the (ADXIEMenuItemClickEventArgs)e.selection to get the selected text and then creating range for the same. But my requirement is to get the last selected paragraph and also get the entire text in the paragraph eventhough only part of the paragraph is selected. Please suggest me a solution for the same.
Note: User can select multiple paragraphs and click on context menu...
Thanks and Regards,
Anoop |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Anoop,
You can use the 'parentElement' property of the selected element to search for the parent paragraph.
Also you can use the mshtml.IHTMLTxtRange interface to learn more about the selection.
private void adxieContextMenuCommandItem1_OnClickEx(object sender, ADXIEMenuItemClickEventArgs e)
{
mshtml.IHTMLSelectionObject selection = e.Selection as mshtml.IHTMLSelectionObject;
mshtml.IHTMLTxtRange textRange = selection.createRange() as mshtml.IHTMLTxtRange;
} |
|
Anoop Kovoor
Posts: 19
Joined: 2012-11-06
|
I tried using the 'parentElement' property of "mshtml.IHTMLTxtRange" and I could see that only when the last paragraph is selected completely the parentElement property is returning the last selected paragraph. Otherwise the 'parentElement' property is returning the 'body' element only. Also please provide the solution if possible to get the entire paragraph text eventhough part of paragraphs are selected. Your assistance and guidance will be deeply appreciated. |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Anoop,
Please try the code below:
mshtml.IHTMLSelectionObject selection = e.Selection as mshtml.IHTMLSelectionObject;
if (selection != null && selection.type == "Text")
{
mshtml.IHTMLTxtRange textRange = selection.createRange() as mshtml.IHTMLTxtRange;
mshtml.IHTMLElement parent = textRange.parentElement();
MessageBox.Show(this, parent.innerText);
} |
|