I want to show a YouTube video inside a WebBrowser control, but I want to disable all user interactions (no mouse clicks no keyboard events...).
I am catching all control's preview, mouse and keyboard events and furthermore I put some handlers to the loaded HTML document, but without any success:
void webBrowser1_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e ) { if(webBrowser1.Document != null) { var doc = webBrowser1.Document; doc.Body.Style = "overflow:hidden"; doc.Click += htmlDoc_Click; doc.MouseDown += htmlDoc_MouseDown; doc.MouseMove += htmlDoc_MouseMove; webBrowser1.Document.Body.Click += new HtmlElementEventHandler(htmlDoc_Click); webBrowser1.Document.Body.MouseDown += new HtmlElementEventHandler(Document_MouseDown); webBrowser1.Document.Body.MouseUp += new HtmlElementEventHandler(Document_MouseMove); webBrowser1.Document.Body.MouseUp += new HtmlElementEventHandler(Document_MouseUp); HtmlElement head = doc.GetElementsByTagName("head")[0]; HtmlElement mscript = doc.CreateElement("script"); IHTMLScriptElement element = (IHTMLScriptElement)mscript.DomElement; element.text = "function handleMouseEvent(e) { " + "var evt = (e==null ? event:e); " + "return true; } " + "document.onmousedown = handleMouseEvent; " + "document.onmouseup = handleMouseEvent; " + "document.onclick = handleMouseEvent; "; head.AppendChild(mscript); } } Also it would be fine to overlay a transparent Control "in front of" the WebBrowser control.
e.Handled = True;as well ase.SuppressKeyPress = Trueon the key down events.