■72944 / ) |
Re[5]: エンターを押せないようにする |
□投稿者/ 魔界の仮面弁士 (69回)-(2014/08/02(Sat) 10:29:11)
|
■No72943 (よしむら さん) に返信 > if (event.keyCode == 13) return false; > のeventの部分にエラーがでてどのように組み込めばできるのかわかりませんでした。
event は C# の予約語です。それがエラーになるという事は、 JavaScript としてではなく、C# のコードとして記述されたのでは無いでしょうか。
こちらでも試してみました。
private void button1_Click(object sender, EventArgs e) { webBrowser1.Navigate("http://www.yahoo.co.jp/"); }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { var textBox = webBrowser1.Document.GetElementById("srchtxt"); var button = webBrowser1.Document.GetElementById("srchbtn");
if (button != null) button.AttachEventHandler("onclick", delegate { MessageBox.Show("検索しましたね!"); });
// これらの方法では、ブロックできなかった // if (textBox != null) textBox.SetAttribute("onkeydown", "if (event.keyCode == 13) return false;"); // if (textBox != null) ((dynamic)textBox.DomElement).onkeydown = "if (event.keyCode == 13) { event.returnValue = false; }";
// これならブロックされた //if (textBox != null) textBox.AttachEventHandler("onkeydown", (elm, arg) => //{ // // 「event」 は C# の予約語なので、「@event」 と記述する // var evt = ((dynamic)webBrowser1.Document.Window.DomWindow).@event; // if(evt.keycode == 13) evt.returnValue = false; //});
// これでもブロックできた //if (textBox != null) textBox.KeyDown += (element, args) => //{ // if (args.KeyPressedCode == 13) args.ReturnValue = false; //};
// これでもブロックできた //if (textBox != null) textBox.KeyPress += (element, args) => //{ // if (args.KeyPressedCode == 13) args.ReturnValue = false; //}; }
|
|