Grab Text From Other Window
-
Hi all, I'm making a little dictionary program in C# for experimenting purposes. everything is coming along fine except how to select the word that is currently under the mouse when the user presses. in VB6 it was done through an API as i remember, but i don't recall which, but this shold be a .net framework program, so better without any win32 api Thanks in advance
-
Hi all, I'm making a little dictionary program in C# for experimenting purposes. everything is coming along fine except how to select the word that is currently under the mouse when the user presses. in VB6 it was done through an API as i remember, but i don't recall which, but this shold be a .net framework program, so better without any win32 api Thanks in advance
If You use
RichTextBox
you can useGetCharIndexFromPosition
to get the word this simple exampleprivate string GetWordFromPos(Point p) { string word; int cIdx=richTextBox1.GetCharIndexFromPosition(p); //go left int startPos; for(startPos=cIdx;startPos>0;startPos--) { string c=richTextBox1.Text.Substring(startPos-1,1); if(c == " ") // add more seperator check here break; } //get the left part word=richTextBox1.Text.Substring(startPos,cIdx-startPos); //go right for(startPos=cIdx;startPos
If you use `TextBox` then `TextBox` didn't have equivalent method or as i know so you need to use `SendMessage` Windows API to Function to send `EM_CHARFROMPOS` to get the index of the Char and Modify the previous function to take to get the text for more inf o look at [EM_CHARFROMPOS Message](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp "New Window")] MCAD -- modified at 22:30 Tuesday 13th September, 2005
-
If You use
RichTextBox
you can useGetCharIndexFromPosition
to get the word this simple exampleprivate string GetWordFromPos(Point p) { string word; int cIdx=richTextBox1.GetCharIndexFromPosition(p); //go left int startPos; for(startPos=cIdx;startPos>0;startPos--) { string c=richTextBox1.Text.Substring(startPos-1,1); if(c == " ") // add more seperator check here break; } //get the left part word=richTextBox1.Text.Substring(startPos,cIdx-startPos); //go right for(startPos=cIdx;startPos
If you use `TextBox` then `TextBox` didn't have equivalent method or as i know so you need to use `SendMessage` Windows API to Function to send `EM_CHARFROMPOS` to get the index of the Char and Modify the previous function to take to get the text for more inf o look at [EM_CHARFROMPOS Message](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp "New Window")] MCAD -- modified at 22:30 Tuesday 13th September, 2005
The problem is, I want to use this function on the text in other windows, not in my program. and i can't be sure if it'll be a rich textbox, textbox, label or any other control that will be read. I read the "EM_CHARFROMPOS Message" but it makes little sense to me. high word, low word... it all doesn't sound the c# level. was that in the C++ time?