c# - Is it possible to bypass RichTextBox input -
i have richtextbox (rtb_inputfield). whenever type in rtb, , press enter, send string typed server. put same string rtb_inputfield , select programmatically (this way user can send same data quickly, pressing enter again - or send string starting type it.) , far.
now want is: if numlock locked , press of numpad keys (0-9) want bypass rtb_inputfield completely. bypass mean: not type of numbers rtb, , instead handle these numbers directly elsewhere. (i'm planning send data server way, while last command user wrote in rtb remains unchanged.)
but if numlock not locked want numpad put numbers rtb.
is possible , how?
here's code have @ moment: (i have modified see what's relevant question.)
private list<keys> numpadlist = new list<keys>(); private void populatenumpadlist() { numpadlist.add(keys.numpad0); numpadlist.add(keys.numpad1); numpadlist.add(keys.numpad2); numpadlist.add(keys.numpad3); numpadlist.add(keys.numpad4); numpadlist.add(keys.numpad5); numpadlist.add(keys.numpad6); numpadlist.add(keys.numpad7); numpadlist.add(keys.numpad8); numpadlist.add(keys.numpad9); } private void rtb_inputfield_keydown(object sender, keyeventargs e) { if ((numpadlist.contains(e.keydata)) && (iskeylocked(keys.numlock))) { //the user pressed numpad key messagebox.show("you pressed: " + e.keydata.tostring()); e.handled = true; } } private void rtb_inputfield_keyup(object sender, keyeventargs e) { richtextbox inputfield = (richtextbox)sender; string userinput = inputfield.text.trim(); if ((e.keydata == keys.enter) && (sender == rtb_inputfield)) { if (client.connected) { macrostring = runinputthroughmacrodictionary(userinput); //do stuff.. writer.writeline(macrostring); } } //lots of other stuff.. }
this code have works in sense: triggers if numlock locked, , messagebox tells me numkey pressed. -but doesn't bypass richtextbox want.
in keypress event handler, set e.handled
true
when think have done , richtextbox shall not proceed key.
private void richtextbox1_keypress(object sender, keypresseventargs e) { if (_tobeignored) { e.handled = true; return; } } private bool _tobeignored; private void richtextbox1_keydown(object sender, keyeventargs e) { if (iskeylocked(keys.numlock)) { _tobeignored = true; return; } }
Comments
Post a Comment