HTML viewing and editing component for WinForms apps

Heres some sample code that allows you to incorporate HTML viewing and editing into your own Windows Forms app.
A couple of people asked for such a thing at the TechEd and I've been meaning to put this out for some time now anyway, since I got my blog together... so here it is.

You can download the sample code (which is provided as-is) to incorporate HTML viewing and basic editing into your own Windows Forms application. Its actually based on the an early prototype from which Web Matrix grew out of.

Feel free to post comments about the code using the comments link below... won't promise any future updates at this time though I would love to hear them anyway, in case I find a chunk of free time.
Posted on Wednesday, 6/4/2003 @ 2:23 PM | #Projects


Comments

32 comments have been posted.

Lawrence Oluyede

Posted on 6/4/2003 @ 2:30 PM
I've got a question to ask you in private email... how can I contact you privately?
If you want, please reply to my email address (l.oluyede[at]virgilio.it)

Scott

Posted on 6/5/2003 @ 6:07 AM
Hi Nikhil,

Thanks for posting the code!

I might be missing something obvious, but is there a method to get the currect text position within the editor? I would love to be able to create a couple of custom forms for inserting pieces of HTML.

Thanks,
Scott

Darren Neimke

Posted on 6/5/2003 @ 5:44 PM
Thanks Nikhil... came just in time for my latest app :-)

Gabriel Schwartz

Posted on 6/11/2003 @ 5:45 AM
Hi,
Nice and quick control but it's not displaying images.
Something I am missing?

Gabriel Schwartz

Posted on 6/11/2003 @ 5:47 AM
Forgot to put my email so here it is: I_HATE_SPAM_Gabriel.Schwartz@amdocs.com <Delete I_HATE_SPAM_>

Luca MIlan

Posted on 6/12/2003 @ 12:24 AM
Very useful, but how can I do for insert the images, any documentation....
thx!

Philipp Schumann

Posted on 6/14/2003 @ 1:11 PM
Hi Folks,
don't you realise that, being provided as source code, it's up to you to display images...?

Philipp Schumann

Posted on 6/15/2003 @ 8:30 AM
@Gabriel and Luca: Not sure what's wrong at your end, but I've just compiled the thing and run it, and it displays images without problems. Haven't tried relative paths, though. Compiled with .NET 1.0 / VS.NET 2002

Michael Earls

Posted on 6/25/2003 @ 7:23 AM
Images bring up problems with local paths (if you insert an image in the MSHTML document, it sets the src to the actual local path). If you add image support, make sure your image is already accessible to your end user and then reference it using (recommended) an absolute URL (or be prepared to write some code).

To add image support, simply add a method in HtmlDocument.cs:

public void InsertImage(){
_editor.ExecPrompt(Interop.IDM_IMAGE);

}

When you wish to add an image, simply call _htmlEditor.Document.InsertImage().

This will open the image dialog and let you set it up. Just remember, the responsbility of getting any local pathed images up to the server is up to you (and converting the src to the new URL). You may wish to keep a table of all of your images and provide a mechanism for uplaoding images, but that's a bit of work. The easiest thing is to upload the images first, and then reference them via a URL with the editor. Probably out of the scope of an HTML Editor control (more in-scope to something like, say... FrontPage?)

Notice the use of ExecPrompt(). You can use _editor.Exec(string ImagePath) if you wish to provide your own dialog for image attributes. The one built into the MSHTML document should serve you nicely for most uses.

Hope this helps.

Nice work, this is a much better alternative than using COM interop with AxSHDocVw. Thanks for the extra work Nikhil.

Michael Earls

Posted on 6/25/2003 @ 7:31 AM
My comment below is hard to read due to problems with newlines, so I have posted a copy on my website.

http://www.cerkit.com/rss_feed/getStory.aspx?id={9AD85F6F-8244-4EFE-8CB4-409A0342290E}&channelId={4B1F3B23-21A9-44E6-9541-07530DFCDA27}#comments

meisam

Posted on 7/15/2003 @ 10:31 AM
how can we set the charset of control to unicode?

Julie Lerman

Posted on 12/4/2003 @ 2:25 PM
Nikhil-
I spent hours today trying to get the dhtmlEdit control to do anything and found your control. I threw together a blogging tool for tablet pc's (just the start of one) and posted it. I couldn't have done it without your control. Thanks!! See it here: www.julialermaninc.com/blog

Michael Yarbrough

Posted on 11/3/2004 @ 5:57 AM
I am making an editor for email much like Outlook. I would like the text to wrap at a specified margin on the right before the horizontal scrollbar is displayed. Any ideas on how to do this? BTW - Style sheets don't work for this since we are editing the actual HTML.

joejoe

Posted on 11/14/2004 @ 3:56 AM
Hallo,

your control is quite interesting and I wanted to know how to chnage the Font and Site.
In "Writer" it is done with a ComboBox but I want the normal FontDialog.
Thanks.

joejoe

prashant

Posted on 1/26/2005 @ 5:10 AM
hi Nikhil,

your control prints fine. i have implimented readystatechanged evnet and called print method which send print command direct to the printer. its work fine for single printing but if i implement for bulk printing(called print from loop). its work fine only problem is not able to get printout in the same order as called print into the loop.

thanks,
Prashant Soni

Jeti

Posted on 1/31/2005 @ 1:15 AM
I can't load localized content.
HtmlControl1.LoadHTML("testing šđčćž");

output is not correct. I inserted following line too:
_site.MSHTMLDocument.SetCharset("iso-8859-2");
in the "protected override void OnHandleCreated(EventArgs args)" method, but no succsess...

please help

Cole Ragland

Posted on 3/21/2005 @ 5:46 PM
sample ASP.NET code that is capable of doing the following:

1. Load in a client-side digital certificate.

If anyone but the owner of the IIS process installs the .pfx file, the IIS user seems to have difficulty in obtaining the private key needed to properly load the cert. One customer just decided to let the IIS user install the cert and worked around the problem. Another customer doesn't want to have to grant the IIS user login permissions for security reasons. Technically, with the tool (WinHTTPcertcfg) customer should be able to grant full permissions to any user for any cert. He tried that, but the error still persists. FYI: that is because he used the -c LOCAL_MACHINE\MY option instead of -c CURRENT_USER\MY. For some reason certifcate will not load with LOCAL_MACHINE.

2. Read in an XML request file (or use a built in text block stored in a variable).

3. Post the XML request to a CREDCOConnect URL.

4. Retrieve the XML response file and display to STDOUT or an output file.

z

Posted on 5/7/2005 @ 11:37 PM
putting this code in a dll that is going to be registered as com so com stuff can consume breaks windows. Tried to put in a dll that MS access is going to use.
It literally breaks windows. IE crashes along and other stuff.

was able to recreate after doing fresh installs. tommorw going to reinstalll windows and put this code in another assembly that is not com visible. see if that works.

css

Posted on 6/19/2005 @ 12:10 PM
Does this component provide css support?

pansiom

Posted on 6/25/2005 @ 10:30 AM
Hallo,
i want to realize the editor as Outlook Express.

thanks.

Max

Posted on 8/19/2005 @ 4:03 AM
Hi,
I've this kind of problem: when I use this control in a Dialog (MyClass.ShowDialog(this)) when I close thi dialog (DialogResult = DialogResult.OK) then the parent form hide(?!?).
Please someone help me.

Nikhil Kothari

Posted on 2/11/2006 @ 1:02 AM
what happens if I post with your name? just checking..

Ooops

Posted on 2/11/2006 @ 1:04 AM
Hi Nikhil, I see that anycone can post as you in your own blog!! I think you must do some checking against the entered name and email and then allow the user to post! Sorry for the test.. :)

Bassam Basamad

Posted on 3/14/2006 @ 3:42 AM
Hi..
How i can do like MS Frontpage ..when i write any char in Disign View..it autumitcally writes in html view..i think on KeyPress..!! ..ok how i can fetch the char that has been pressed and i putted in html view..in the same carret..pos and same line where i write..the character..

please use front page..to see how it do that..

And also ..when i write on html View it write the text in RTF mode..means it saves the \n and others values..
so when go to Design View..it interpres to html everything ok..but when i go back to html View..it is not returning the rtf that it has been before..

thanks..for control

vitaliy

Posted on 3/24/2006 @ 2:55 AM
Hi, all!
I want to thank the author very very much!
I spended 2-3 days to find the similar thing and finally i found it.
Thank you again!

Ricardo Ildefonso

Posted on 3/30/2006 @ 2:44 PM
Hi and thanks!!

But, how can I make it accept my formating (i.e.: ever use Tahoma font and don't skip lines between paragraphs) ?

Nuwan

Posted on 6/7/2006 @ 4:36 AM
HI Nikhil,
I'm looking for a printing solution via .Net windows forms. My requirement is to print the .doc, .rtf and .pdf files inside a folder. I have search lot of articles but no one explaning the way of sending a file in to the printer, really i want to print a that file with our openning.

Pls give me some trick s and tips to do that

Thanks
Nuwan

Ramesh

Posted on 6/20/2006 @ 5:29 AM
Hi,

I am using this control to render html. But i want that the control auto resize it self exactly to the size of html content in it. How can this be done. Please help me out.

codesque

Posted on 6/29/2006 @ 3:21 AM
Hi Nikhil,

just want to thank you for this real good code base. It's a fine thing to start with. I already extended code to support basic editing caps and custom glyphs. Thanks again.

acha11

Posted on 7/18/2006 @ 1:24 AM
I ran into and fixed an issue with this code under .NET 2.0. I had a form containing a button and an instance of the HtmlEditor control. The button was labelled "&Save", and so had a mnemonic (shortcut key) "S". When focus was on the HtmlEditor Control, any letter I typed would show up correctly except "S", which would trigger the Save button's click event.

The fix was to add this code to HtmlControl.cs.

protected override bool IsInputChar(char charCode)
{
return !char.IsControl(charCode);
}

Hope this saves someone else some time.

Arun.K

Posted on 8/24/2006 @ 10:32 PM
Hi Nikhil,
I would like to use the Timer component in my web page. If any one opens my web site, it will close after 30 minutes from when they opened my page.

If there any component in HTML?

If it is there please give idea and Code in HTML to use it...

Arun.K

Posted on 8/24/2006 @ 10:38 PM
How do i set the time in html?
when the time expires,the web page will automatically close...
how will i do it?
The discussion on this post has been closed. Please use my contact form to provide comments.