I'm struggling with the WebBrowser
control (both in Winforms and WPF). Basically I want to achieve the same behavior I got with a RTF
editor: Handling some kind of OnTextInput
event in order to get the last typed character for every keystroke.
I mean the textual characters, not Control, Alt, F5, Enter, ... that can be captured with the Keydown/Keyup
events.
Any help? Thanks in advance.
答案 0 :(得分:1)
您可以KeyPress
this.webBrowser1.Document.Body
发生private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
//Attach a handler to DocumentCompleted
this.webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Attach a handler to Body.KeyPress when the document completed
this.webBrowser1.Document.Body.KeyPress += Body_KeyPress;
}
void Body_KeyPress(object sender, HtmlElementEventArgs e)
{
//handle the event, for example show a message box
MessageBox.Show(((char)e.KeyPressedCode).ToString());
}
事件。
e.ReturnValue = false;
注意:强>
KeyUp
来取消输入。KeyDown
和-(void)buttonAction:(UIButton*)sender{
for(UIView* view in self.view.subviews){
if([view isKindOfClass:[UIButton class]] && view != sender){
UIButton *btn = (UIButton *)view;
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // set color whichever you want
}
else{
[sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // set color which ever you want
}
}
}