Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not fluent in C#, and I am also brand new to this forum. However, it looks to me like if you were to supplement the code rene posted with a function which queries your Translation table and returns the translation text, you would then have this (forgive my pseudo-code butchery - I am very fluent in vb.net, gonna learn the C# syntax soon):</p> <pre><code>Private String TranslatedWord(ByVal SelectedWord String) { //Use ADO and SQL to retrieve the Translation(s) associated with the submitted Word // A string SQL Statement (the GROUP ON is in case there are multiple instances of the same word, with different translations (synonyms). THis SQL Should return a a single record for each possible translation of the submitted word (more than one result possible): Dim SQL as String = _ "SELECT tr.ID, tr.Translate " &amp; _ "FROM MyTranslationTable AS tr " &amp; _ "WHERE tr.Word LIKE @Word" //Since I could be ALL DAY struggling to write the C# code for this, I will just step through it in "pseudocode": // 1. Execute the SQL using ADO.Net, set up the @Word Param in your command, and return a sqlDataReader // 2. Iterate through the returned records, and append the Translation results to a System.Text.Stringbuilder object. Delimit each returned value with a semi-colon (or your delimiter of choice). // Return the Stringbuilder.ToString property as the result of this function; </code></pre> <p>}</p> <p>Then change the last part of rene's code ("//Show the result") as follows (suitable corrected for my horrible C# problem!):</p> <pre><code> private void richTextBox1_MouseMove(object sender, MouseEventArgs e) { // whitespace definition char[] whitespace = new char[] { ' ', '\r', '\n', '\t' }; int charPosition = this.richTextBox1.GetCharIndexFromPosition(e.Location); string fullText = this.richTextBox1.Text; // if we are on whitespace, exit if (whitespace.Contains(fullText[charPosition])) { return; } // find a whitespace towards the start of the text int firstWhiteSpace = charPosition; while (firstWhiteSpace &gt; 0 &amp;&amp; firstWhiteSpace &lt; fullText.Length &amp;&amp; !whitespace.Contains(fullText[firstWhiteSpace])) { firstWhiteSpace--; } if (firstWhiteSpace!=0) firstWhiteSpace++; // find the next whitespace int lastWhiteSpace = fullText.IndexOfAny(whitespace, charPosition); if (lastWhiteSpace == -1) lastWhiteSpace = fullText.Length; // substring the word out of the flat text string word = fullText.Substring( firstWhiteSpace, lastWhiteSpace - firstWhiteSpace); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //My CHanges start here, and will likely require // some tweaking . . . //Use the function I have poorly described above to retreive the //translation(s) for the current Word: string TRANSLATION = TranslatedWord(word); // show the result //Since there are so many minor but important differences between C# and VB, I am not going to attempt //to account for them. Essentially, display the translated word instead of the word over which the mouse is hovering: label1.Text = String.Format("pos:{0} fsp:{1}, lsp:{2}, len:{3}, word:{4}", charPosition, firstWhiteSpace, lastWhiteSpace, fullText.Length, TRANSLATION); } </code></pre> <p>If it would be helpful, I could bust out the vb.net code for this fairly quickly, but I wasn't going to do that unless it would be helpful. </p> <p>Hope that's helpful. I am going to have to work a little at learning C#, and at improving my understanding of posting in this forum! Getting the code to look right is proving a challenge . . .</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload