question

JonJacobs-9073 avatar image
0 Votes"
JonJacobs-9073 asked DanielZhang-MSFT commented

Find and Use Selected Text in WebBrowser Control

In my WebBrowser control in a dialog in my C# winforms application I have a 2-column HTML table. When I display the dialog with the browser I select text in the second column. I need to get the selected text, and the whole text of the column in that row, and the text of first column in that row.
How do I do that? I am processing it it ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F1) { //webBrowser1.? } return base.ProcessCmdKey(ref msg, keyData); }

dotnet-csharpwindows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DanielZhang-MSFT edited

Hi @JonJacobs-9073
First please check if Ash's code is helpful to you.
>> I need to get the selected text, and the whole text of the column in that row, and the text of first column in that row.
Provide more code about your HTML table and explain in detail.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JonJacobs-9073 avatar image
0 Votes"
JonJacobs-9073 answered DanielZhang-MSFT commented

Thank you so much for your response.

F

irst please check if Ash's code is helpful to you.

Where do I find Ash's code?

Here is an example of the HTML table generated as a result of search criteria:
<table align='center' border='3' cellpadding='2' cellspacing='2'>
<tr>
<th align='' width='65'>Ref</th>
<th align='' width='860'>Verse</th>
</tr>
<tr>
<td align='left' width='65'><font face='Courier New' size='4'>MATT.6:25</font></td>
<td align='left' width='860'><font face='Courier New' size='4'><span style="color:red">Therefore I say unto you, Take no thought for your life, what ye shall eat, or what ye shall drink; nor yet for your body, what ye shall put on. Is not the life more than meat, and the body than raiment?</span></font></td>
</tr>
<tr>
<td align='left' width='65'><font face='Courier New' size='4'>MATT.6:27</font></td>
<td align='left' width='860'><font face='Courier New' size='4'><span style="color:red">Which of you by taking thought can add one cubit unto his stature?</span></font></td>
</tr>
<tr>
<td align='left' width='65'><font face='Courier New' size='4'>MATT.6:28</font></td>
<td align='left' width='860'><font face='Courier New' size='4'>And why take ye thought for raiment? Consider the lilies of the field, how they grow; they toil not, neither do they spin:</font></td>
</tr>
<tr>
<td align='left' width='65'><font face='Courier New' size='4'>MATT.6:31</font></td>
<td align='left' width='860'><font face='Courier New' size='4'><span style="color:red">Therefore take no thought, saying, What shall we eat? or, What shall we drink? or, Wherewithal shall we be clothed?</span></font></td>
</tr>
<tr>
<td align='left' width='65'><font face='Courier New' size='4'>MATT.6:34</font></td>
<td align='left' width='860'><font face='Courier New' size='4'><span style="color:red">Take therefore no thought for the morrow: for the morrow shall take thought for the things of itself. Sufficient unto the day <i>is</i> the evil thereof.</span></font></td>
</tr>
</table>
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JonJacobs-9073,
I have added a link to Ash's code in the comments above, you can refer to.
Best Regards
Daniel Zhang

1 Vote 1 ·

Thank you for the link! I have seen several references to mshtml and IHTMLDocument2 in postings, but this is the only one I have seen that explains how to get to it. I will check it out.

0 Votes 0 ·

Hi @JonJacobs-9073,
Please let me know if there is anything that I can help here.
Best Regards,
Daniel Zhang

0 Votes 0 ·
Show more comments