Note that there are some explanatory texts on larger screens.

plurals
  1. POc# WYSIWYG editor using webbrowser and richtextbox
    text
    copied!<p>Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here and other place.</p> <p>Im using a webbrowser for the design state of the editor, but i need to be able to switch to "html-view" so I used a rich textbox, and my tought was to just grab the content from the webbrowser and set it to the rtb, and the other way around.</p> <p>It works fine until i try to put back the value from the rtb into the webbrowser, then i get a "This document has changed, do you want to save the changes"-alert and after that the webbrowser wont accept new content.</p> <p>Any idea what to do? Or any other way to handle the solution im after?</p> <p>the code:</p> <pre><code>namespace EmailAdmin { public partial class Form1 : Form { // global variables private IHTMLDocument2 doc; private int WYSIWYGviewState = 0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // initiate web browser to design mode webBrowserWYSIWYG.DocumentText = "&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;"; doc = webBrowserWYSIWYG.Document.DomDocument as IHTMLDocument2; doc.designMode = "On"; } private void linkSwitchWYSIWYGview_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { // determins viewstate // is design view if (WYSIWYGviewState == 0) { // set html view WYSIWYGviewState = 1; rtbWYSIWYG.Visible = true; // populates the texteditor with html rtbWYSIWYG.Text = webBrowserWYSIWYG.DocumentText; // change label text linkSwitchWYSIWYGview.Text = "View Design"; } // is html view else if (WYSIWYGviewState == 1) { // set design view WYSIWYGviewState = 0; rtbWYSIWYG.Visible = false; // populates the designer with html webBrowserWYSIWYG.DocumentText = rtbWYSIWYG.Text; // change label text linkSwitchWYSIWYGview.Text = "View HTML"; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload