Update 12/18/2013:

Added a few samples of how to implement in epicor / integrate with the data views. Please not that if you are going to paste images and use it with Epicor we recommend that you download the version which puts the images on a shared network drive. Most UD fields in epicor are too small to handle the Base64 encoded image.
This sample code is provided as is and it was created using Epicor 9.05


Update 12/3/2013:


Joshua Giese from Perficiency Development made some enhancements to the editor that he wanted to share back.

  1. Added the ability to copy / paste images.
    Images are pasted and embedded using the Base 64 Data URI
    or Images are placed on a Shared Folder in a Network Drive ( 2 different versions see below)
    2013-12-03 13_42_47-6lAYWRgVoJqMXSzcdRWj2plP5W0KN.jpg (950×627)
  2. Added a custom context menu for Copy , Cut and Paste which invokes the toolbar functions
    6lAYXWo8vaSq3lSI7XvEaW77UFdYD[1]
  3. Also the project has been upgraded to Visual Studio 2012

Download it here HTMLWYSIWYG (Base 64 Encoded Image)

Download it here HTMLWYSIWYG_sharedFolder (Shared folder Paste Image)


I’ve been busy at work lately one of the projects assigned to me is to create an application to redact and edit emails that will be sent to customers. This provided a great opportunity for me to get familiar with creating a custom control in C#. I needed a way to create rich content and although C# has the rich text control it provides everything in RTF which is difficult to work with and hard to embed. So I got to work on my very own WYSIWYG control that produces HTML. So I am making it open source and available to anyone have fun and enjoy if you make any cool modifications to it let me know. I would love to include spell check ability but I don’t have much time to work on it right now.

Download Here HTMLWYSIWYG (Original version)
wysiwyg

Sample Uses

 private void button1_Click_1(object sender, EventArgs e)
 {
 //Gets the HTML Code generated by the control
 Console.WriteLine( htmlwysiwyg1.getHTML())
 //Getts the PLain Tex code generated by the control.
 Console.WriteLine(htmlwysiwyg1.getPlainText());
 }
 

 

 private void frm_main_Load(object sender, EventArgs e)
 {
 //Sets the control to allow edits
 htmlwysiwyg1.allowEdit(true)
 //Loads the HTML into the control
 htmlwysiwyg1.setHTML("BOLD");
 //Loads aditional fonts into the control
 htmlwysiwyg1.addFont("Cambria");
 htmlwysiwyg1.ImagePasteToPath =@"\\YOUR_UNC_PATH"; //Only available in the Paste to Network Version
 }
 
Be Sociable, Share!

Tags: , , , , ,

21 Comments on C# WYSIWYG HTML Editor

  1. alan328 says:

    Nice work !

    I like it !

    But the AssemblyInfo.cs and Resources.resx are missing !

    Can you email them to me? Thanks a lot !

  2. Jose C Gomez says:

    Alan,
    Thanks for the heads up I have fixed it and uploaded a new one.

  3. Jeff Williams says:

    I have downloaded your html editor but cannot get it to work. It has and error as below. Do you have any ideas why.

    System.NullReferenceException: Object reference not set to an instance of an object.
    at HTMLWYSIWYG.htmlwysiwyg.setHTML(String html) in d:\Projects\CSharp\Third Party\HTMLWYSIWYG\HTMLWYSIWYG\htmlwysiwyg.cs:line 48

    public void setHTML(String html)
    {
    doc.body.innerHTML = html;
    }

  4. Juan Rebollo says:

    Nice!
    Thanks a lot!

    Gracias, lo he utilizado en un proyecto para creación y envio de emails!

  5. […] VS 2008 C# WYSIWYG HTML Editor | josecgomez.com Premi se vuoi commentare l'intervento. "HeloWorld.exe" 17 errors, 31 warnings. […]

  6. Carlos Santana says:

    Thanks, this is great!

  7. Bzzz says:

    THANK YOU!

    Is there TextChanged event?
    How to check Text Changing?

  8. George Lekas says:

    Same problem as Jeff Williams

    Control throws NullReferenceExceptions

    Good work but unstable

  9. Alain L. says:

    Me too. I have the same problem as Jeff Williams and George Lekas.
    Found any workaround guys?

    • Jose C Gomez says:

      Alain,
      If you shoot me a sample of the error you are getting I may be able to help. I haven’t looked at this in quite a while but I’ll give it a try.

  10. Joel P. says:

    Looks cool! What’s the license for the sources?

  11. Ruan Fourie says:

    Excellent work!

    For those getting the System.NullReferenceException when setting the html, you have to set it after the control has been loaded. For instance you can’t set the html in the constructor of your form but rather in the OnLoad event as shown by Jose.

    It works very well on my side. Thanks Jose!

  12. […] Go download the appropriate version of the DLL from the original post […]

  13. Michael Schwarz says:

    For those coming here looking for the solution to the NullReferenceError on setHTML, add this at the top of the setHTML function:

    while ( doc.body == null )
    Application.DoEvents();

  14. Net says:

    Nice job, thanks for that. But I need to know is the use in a commercial application allowed?

  15. Net says:

    What a quick reply! another question: can I put this custom control in the VS toolbox?

  16. Net says:

    Jose C Gomez, what do you think distribute the WYSIWYG HTML Editor as a Custom Control so that it can be added to ToolBox? is a lot easier to put it from the ToolBox and drag-and-drop it as control and move around.

  17. Hyunjin Kim says:

    Thanks a lot! This is exactly what I’m looking for.