Solve this problem thanks to the @ liust brothers http://www.cnblogs.com/somtomking/archive/2012/03/02/2376800.html
The problem is that there is a place where rich text needs to be used. Because it is a winform program, and the program is left by the previous generation of employees, there are hundreds of errors. Now we should try to fix it as much as possible, at least ensure that the service can be used normally, so a little problem is fixed.
In win7 64-bit system, the editing status cannot be activated, or the cursor cannot be obtained. In short, no characters can be written.
I started to suspect that the reason was 32-bit and 64-bit. After compiling a 64-bit version test, the result still failed.
I found an article by @ liust renxiong. Suddenly, it turned out to be ie9, which is not 64-bit. The problem still needs to be solved because ie9 can only be installed on win7 64-bit.
Directly copying the following code seems to be useful, but other problems occur.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.Version.Major >= 9) { webBrowser1.Document.Write(webBrowser1.DocumentText); doc.designMode = "On"; } }
Of course, the blogger forgot to register the event.
To be in private void SetupBrowser ()
Register an event
WebBrowser1.DocumentCompleted + = new WebBrowserDocumentCompletedEventHandler (webBrowser1_DocumentCompleted );
Because my system was left by older generation employees, there are some other code in the DocumentCompleted event.
A new problem occurs. "This document has been modified. Do you want to save the Modification result? "
This problem occurs, and the search continues, taking some detours.
WebBrowser1.Document. Write (webBrowser1.DocumentText); it should be a curse.
But how can we load data and avoid modifying the value of the control in this place? My idea is to load the data before setting On.
When a focus event is detected during debugging, it first goes to this function.
Private void SetupBrowser (bool edit)
There is a flag in this function: edit
If it is true, doc. designMode = "On" is set"
After that, I did some other operations and did not take a closer look.
Why is it necessary to set "On" again when DocumentCompleted is reached?
I guess it would be better to debug it, So I installed IE9 and started debugging.
When the program runs to DocumentCompleted in IE9, The designMode in ie9 is "Inherit"
No wonder you have to set "On" again. So according to the edit in SetupBrowser (bool edit), the code is modified in DocumentCompleted.
ToolStrip. visible is whether to display the toolbar of the control. It is used directly because it is a global variable, because toolStrip. visible = edit; otherwise, the landlord wants to create a global variable to save the edit state.
If (toolStrip. Visible)
{
If (doc. designMode! = Null & doc. designMode! = "On ")
Doc. designMode = "On ";
}
In fact, my project is also a special case. It may not be helpful to everyone, but I hope to help some of you ~~