I have been developing with WinForm. I think the current WinForm development speed is enough, but some things that have been easily done in HTML, it is difficult to achieve in WinForm. This main reason may be that the WinForm multiplex control is very strong, but the available controls are very small. The controls that typically buy back is not only expensive, but also too good to expand.
As a person who has learned HTML, I certainly hoped to use HTML characteristics in WinForm, such as powerful CSS! , The characteristics of automatic typography telescopic, (CSS and tiben can be more convenient to print!), And script writing. (Sometimes writing scripts is more cool than writing WinForm. Specific situation).
It is actually not difficult to do this. But it is not easy to use flexible.
Usually, people using the WebBrowser control, just simply use the MSHTML to call the webbrowser. In other words, this call is single, considering modifying HTML to display something.
Today I wrote this essay intention to tell you how to feed back the user's operation in WebBrowser to WinForm.
The cornerstone of this feedback is the interopservices for DOTNET. By transmitting an object of the DOTNET to the HTML DOM, then use the script to operate the DOTNET object.
To do this, the core is:
Get webbrowser.document, which implements mshtml.ihtmldocument / 2/3/4/5 (where Ihtmldocument2 is most useful) this document is system.Runtime.InteropServices.expando.iexpando, set and get some dynamic named for Document member.
Examples of code is: mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2) browser.Document; System.Runtime.InteropServices.Expando.IExpando ex = (System.Runtime.InteropServices.Expando.IExpando) doc2; System.Reflection.PropertyInfo piform1 = EX.AddProperty ("Form1"); PiForm1.SetValue (DOC2, this, null); // Since then, Document.form1 in HTML is this WinForm's Control. You can call Form1 with your script!
With these interactions, what we can achieve is too much.
I should study it next step, how to dynamically embress the WinForm's Control into this html. (Not the form of "Object" to deploy)
Transfer from: http://blog.9cbs.net/waxdollcheung/articles/324498.aspx