Click here to Skip to main content
Licence 
First Posted 6 Jan 2006
Views 147,266
Bookmarked 74 times

WYSIWYG HTML Editor

By | 6 Jan 2006 | Article
Building a simple WYSIWYG (What You See Is What You Get) HTML Editor in C#.

Sample Image

Introduction

I have found different code samples showing how to create a visual HTML editor in ASP using a text area. However, I needed a good editor for my WinForms application, but I couldn’t find a good example. Eventually, I wrote one from scratch after I converted some MFC code I found on the net. Based on the IE Browser control, you can create a powerful editor that allows you to manipulate HTML tags visually and add any tags you want.

Using the code

The code is a simple form, and very easy to understand. In order to make it work, you first need to include two COM libraries:

  1. The Microsoft Web Control found in: c:\windows\system32\shdocvw.dll (add as a COM control).
  2. MSHTML: c:\windows\system32\MSHTML.tlb (add as a COM reference).

The reason for the tlb is that the mshtml.dll is used by the Windows system, and therefore is not accessible.

You don't need to worry about deployment: all Windows users will have these DLLs in their system directory.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Shlomo Schwarcz

Web Developer

Israel Israel

Member

Shlomo had worked for several years as a software engineer and project manager, developing software for the enterprise market, in Microsoft.NET and Java J2EE environment. Before establishing Shefer’s SAP department, Shlomo worked at SAP Labs and took part of the NetWeaver and Enterprise Portal development team.
 
Shlomo has many years of experience with SAP customers and has also teaches official SAP courses around the world.
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberSkySoftHelper19:01 9 May '11  
GeneralCongratulations on the good work PinmemberRene.DH10:43 18 Apr '09  
Question[BR /] instead of [P/]? Pinmemberaj3214:18 12 Jun '08  
AnswerRe: [BR /] instead of [P/]? Pinmemberraiserle10:34 21 Dec '11  
QuestionCan I insert tables? PinmemberDrucik_13:02 20 Apr '08  
AnswerRe: Can I insert tables? PinmemberBITS_UK23:13 26 May '08  
Generalcopied imaged from ms word doesn't show PinmembernetJP12L11:21 23 Jan '08  
GeneralImages dont apprear when copied from Ms word PinmembernetJP12L11:15 23 Jan '08  
GeneralThanks, just what I needed Pinmembervictorbos3:21 1 Nov '07  
QuestionProblem with Deploy Different Version shdocvw.dll Pinmembersebandres5:31 20 Feb '07  
QuestionHow can i insert a text in a given position? Pinmemberrespiratory10111:56 26 Sep '06  
AnswerRe: How can i insert a text in a given position? PinmemberHenrik Thulin10:06 28 Jun '11  
Questionhow to change the language of the text Pinmemberalihammad4:22 28 Aug '06  
QuestionWYSIWYG WORD Pinmember123456uio3:16 9 Aug '06  
Questionwhere are html, title, head, meta tags ? PinmemberRobcast20:38 29 Jun '06  
AnswerRe: where are html, title, head, meta tags ? PinmemberRobcast24:00 29 Jun '06  
QuestionAdding Events PinmemberAbhiTheGenius21:50 13 May '06  
Hi,
 
In usual editors (like Word or FrontPage, maybe), when the cursor is moved to a piece of text that is bold or underlined, you'd have the corresponding toolbar items checked.
 
I was wondering how to implement this functionality in this particular editor. I know about the queryCommandState() or Value() or Text() functions, but when do I use it? I can't seem to get events like onselectionchange working properly.
 
Has anybody tried this before?
 
Thanks.
AnswerRe: Adding Events PinmemberShlomo Schwarcz22:33 13 May '06  
GeneralReference PinmemberDeathJester_9:50 26 Mar '06  
QuestionInvalidCastException Unhandled Pinmemberpjrinaldi18:45 18 Feb '06  
AnswerI think I know the problem PinmemberShlomo Schwarcz20:46 18 Feb '06  
QuestionRe: I think I know the problem Pinmemberpjrinaldi4:05 19 Feb '06  
AnswerRe: I think I know the problem PinmemberShlomo Schwarcz4:08 19 Feb '06  
QuestionRe: I think I know the problem Pinmemberpjrinaldi5:03 19 Feb '06  
AnswerRe: I think I know the problem Pinmemberpjrinaldi17:23 20 Feb '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 6 Jan 2006
Article Copyright 2006 by Shlomo Schwarcz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid