Nikolay Nikolay - 20 days ago 7
C# Question

Change webbrowser Cursor

I have a form that contains WebBrowser control.
I need to change the cursor to WebBrowser.

I try

this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.TopLevelControl.Cursor = Cursors.WaitCursor;


The cursor changes form only, but not for WebBrowser.

How can I change the cursor in WebBrowser control?

Answer

Add a reference to your solution to "mshtml.dll". After you load your Document, try this:

IHTMLDocument2 doc = (webDocument1.Document.DomDocument) as IHTMLDocument2;
IHTMLStyleSheet style = doc.createStyleSheet("", 0);
style.cssText = @"body { cursor: wait; }";

Please bear in mind that the result depends also on the way you load the web page (load a local/embedded file, set the DocumentStream, etc.).