Click here to Skip to main content
15,885,038 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
So I'm wondering how it is done, I asked on msdn and viewed the TextBox code and got completely lost so I decided to kindly ask here :)
I simply want to write a method that looks like that

char GetChar(int keycode, bool shiftState, object something/*Arabic(101), Arabic(102), Albanian, English(US), English(UK)...etc CultureInfo maybe*/)
{
    char output = '\0';
    bool capsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;
    //Some code....
    return output;
}
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jul-11 3:24am    
Tag it! WPF, Forms, what?!
--SA

A TextBox (assuming you mean System.Windows.Forms.TextBox - please be specific if not) is actually a wrapper around the Win32 Edit common control, so text is actually posted to a window handle (HWND) and native code in Windows handles processing.

But a TextBox can handle input by overriding OnKeyDown (or handling the KeyDown event if you don't want to subclass).

However, I'm not clear from your question what it is you're trying to do. If we could understand what you're trying to do (and not just a question on a preconceived how) we could better propose a solution.
 
Share this answer
 
Comments
Hesham_h4 9-Jul-11 19:14pm    
Thanks for replying, what I mainly try to do here is to get text in a specified language from text typed in another language.
What I came up with is to convert that text (Given the language/keyboard layout) to a keycode array (Including shift state) then do what I'm trying to do here.
For example if we have the text "فاهس هس ُىلمهسا" that's in Arabic(101), I want to predict the text written in English (Assuming that the user forgot to switch language) which is "this is English".

Of course if there's another way to do that I'd love to know.

P.S: Google is already using such a method in the search bar.
http://imageshack.us/photo/my-images/89/capturece.jpg/[^]
Sergey Alexandrovich Kryukov 10-Jul-11 3:32am    
Sure. In my solution I answered exactly this question (and not your initial question above).
--SA
Sergey Alexandrovich Kryukov 10-Jul-11 3:32am    
Considering you did not read the follow-up question by OP, this is a good answer, my 5. As to this question -- I've answered; please see my solution.
--SA
Espen Harlinn 10-Jul-11 7:37am    
Good reply, my 5
Hesham_h4 18-Jul-11 0:49am    
This is actually the answer to the Title questions though not answering the Main one but I decided to ask it separately.
You should do it handling the event KeyPress. The event arguments of this event will give you the key character pressed; you can compare it with the Unicode code point ranges you expect for input and issue the warning. Alternatively (or better additionally), you can filter out unwanted characters as this event can be cancelled; use the value of property Cancel to true (this is the property if the event arguments parameter).

—SA
 
Share this answer
 
Comments
Espen Harlinn 10-Jul-11 7:50am    
My 5 - If he is going to do it himself, this is where he needs to start - but getting it right might be a bit of a challenge.
Sergey Alexandrovich Kryukov 10-Jul-11 13:33pm    
Thank you, Espen.
Challenge or not, but this is what should be done, no less.
--SA
Espen Harlinn 10-Jul-11 13:50pm    
He could just change the input language for the UI thread of his application - that would be quite easy :)
Sergey Alexandrovich Kryukov 12-Jul-11 16:16pm    
Well, the question is reasonable. (By the way, I don't know how to change input language programmatically, this is not UI culture; do you know? WMI?) So, the question is reasonable: instead of forcing the user into different input it would simply warn and notify which language is expected.
--SA
Espen Harlinn 12-Jul-11 16:50pm    
ehrm ... :blush: ... try looking at my "solution" ...
From the previous discussion I think this is what you need:
InputLanguage.CurrentInputLanguage[^] - this property gets or sets the input language for the current thread.

Use InputLanguageCollection[^] as the source of available input languages.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Hesham_h4 17-Jul-11 23:50pm    
Knowing the input language might help finding out that the input isn't recognized as words in the selected input language and so trigger the whole process. I think you found the trigger, but we still don't have a gun :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900