• (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

Creating a wysiwyg HTML editor in C# Using the MS HTML Object Library

#16 julanna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-May 09

Posted 05 May 2009 - 11:14 AM

I have a question. I am working on a small website editor project and this post has been a great use to me.

The problem that I have is this: I open pages into the editor with a listBox that is populated from a directory. When I first start the app and click on a file to open in the editor it works fine. When i try to open another file into the editor it does nothing.

This is my code:

		

		private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			String file = listBox1.SelectedItem.ToString();
			HTMLEditor.DocumentText = System.IO.File.ReadAllText(file);
		}




How would I reset the editor "if that is what i should do" to open another file after I have opened the first one?
Was This Post Helpful? 0
  • +
  • -

#17 jammmie999  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 117
  • Joined: 01-April 09

Posted 16 May 2009 - 08:38 AM

How do I use Relative links with this. When I type to insert a image at "images/myimage.php" it dont work. How can I make this work with out converting the link to Absolute.

Thanks
Was This Post Helpful? 0
  • +
  • -

#18 SanjitVignesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 19-September 08

Posted 17 May 2009 - 07:56 AM

View Postjulanna, on 5 May, 2009 - 10:14 AM, said:

I have a question. I am working on a small website editor project and this post has been a great use to me.

The problem that I have is this: I open pages into the editor with a listBox that is populated from a directory. When I first start the app and click on a file to open in the editor it works fine. When i try to open another file into the editor it does nothing.

This is my code:

		

		private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			String file = listBox1.SelectedItem.ToString();
			HTMLEditor.DocumentText = System.IO.File.ReadAllText(file);
		}




How would I reset the editor "if that is what i should do" to open another file after I have opened the first one?



I had this same problem while designing my media player. The player does not play the one I click. Instead it plays the one I clicked before.
Was This Post Helpful? 0
  • +
  • -

#19 SBohnen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-July 09

Posted 22 July 2009 - 11:14 AM

Great Solution!
Just wondering: The list of command identifiers:
http://web.archive.o.../commandids.asp
does not include "insert table", so how could that be implemented?
Was This Post Helpful? 0
  • +
  • -

#20 Softwaredevelop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-November 09

Posted 05 November 2009 - 06:24 AM

How to get the text entered in HTML Editor without HTML tags?
We can get text containing HTML tags with
HTMLEditor.DocumentTExt property
But how to get text withou tags in HTML Editor?
Was This Post Helpful? 0
  • +
  • -

#21 Sisco55  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 09

Posted 23 November 2009 - 04:55 PM

Anybody have any ideas to make an editor change between code and visual views with the click of a button? I found some Javascript code on the internet that does a similar thing to a WYSIWYG editor (an online one that needs IE), but I am a relative newcomer to C# and I don't know how difficult it would be to adapt the code for my use, or if it'd even be possible.






<script language="Javascript">

var viewMode = 1; // WYSIWYG

// Other code exists here

function doToggleView()

{

if(viewMode == 1)

{

iHTML = iView.document.body.innerHTML;

iView.document.body.innerText = iHTML;



// Hide all controls

tblCtrls.style.display = 'none';

selFont.style.display = 'none';

selSize.style.display = 'none';

selHeading.style.display = 'none';

iView.focus();



viewMode = 2; // Code

}

else

{

iText = iView.document.body.innerText;

iView.document.body.innerHTML = iText;



// Show all controls

tblCtrls.style.display = 'inline';

selFont.style.display = 'inline';

selSize.style.display = 'inline';

selHeading.style.display = 'inline';

iView.focus();



viewMode = 1; // WYSIWYG

}

}


Was This Post Helpful? 0
  • +
  • -

#22 Guest_sandro*


Reputation:

Posted 15 March 2010 - 09:11 AM

how do I make an event when changing the text on DocumentText?
Was This Post Helpful? 0

#23 Guest_sandrocirlini*


Reputation:

Posted 16 March 2010 - 08:28 AM

how can i disable the automatic showdialogAttached Image?
Was This Post Helpful? 0

#24 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Posted 28 March 2010 - 11:48 AM

I get this error


Error 1 The type or namespace name 'IHTMLDocument2' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Terry June\My Documents\Visual Studio 2008\Projects\Html Editor\Html Editor\Form1.cs 16 23 Html Editor
Was This Post Helpful? 0
  • +
  • -

#25 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Posted 29 March 2010 - 05:56 PM

I converted this code to vb.net which I can understand and I realize when you click on a button on bold then you click on something like underline the whole editor messes up. Could you write this in vb.net(if you know vb.net) because we vb.net programmers would like to know this. Or I could write it so that you can carry on writing useful tutorials.

This post has been edited by VB.Terry: 30 March 2010 - 04:03 PM

Was This Post Helpful? 0
  • +
  • -

#26 Guest_c#.net_help*


Reputation:

Posted 04 April 2010 - 11:54 PM

i m not able to use the web browser control in WPF .The web browser control is disabled in WPF .I i m using the VS 2010. Plz help its urgent.Thanks.
Was This Post Helpful? 0

#27 Guest_BlackOne*


Reputation:

Posted 07 April 2010 - 04:51 AM

Hi I use code in vb.net 2008 and it's working fine to me. I have one question.
I wonna make when I press enter button to clear htmleditor and send that text to another form I know how to clear editor and send text but I need help with connect that function with Enter button in htmleditor
Was This Post Helpful? 0

#28 Black0n3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-April 10

Posted 07 April 2010 - 06:10 AM

I try to this code and it's working but I have 3 problems with that code
  Private Sub HTMLEditor_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles HTMLEditor.PreviewKeyDown
        If e.KeyValue = Keys.Enter Then
            MsgBox(HTMLEditor.DocumentText)
            HTMLEditor.DocumentText = ""
        End If
    End Sub


1. 2 time got a message in msgbox.

2. when he need to clear text he ask me "This document has been modifield. Do you want to save changes".
How can I make that program clear text without assking me that message?

3. I makeing chat program and whan I wonna send messege to server it looks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7600.16535"></HEAD>
<BODY><STRONG>this </STRONG>is <U>test</U></BODY></HTML>



but i need only code inside body tags:
<STRONG>this </STRONG>is <U>test</U>

How can I get that code?

And 4. =)
I made button bold and I made whan button is pressed his chach state go to true and whan is pressed agin hise chackstate go to false I working fine but I have problem whan I select text and press bold selected text goes to bold and chackstae goes to true but whan I continue to write text is not bold how can i fix that i have this code

 Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBold.Click
        HTMLEditor.document.ExecCommand("Bold", False, DBNull.Value)

        If cmdBold.Checked = False Then
            cmdBold.CheckState = CheckState.Checked
        Else
            cmdBold.CheckState = CheckState.Unchecked
        End If


thx =)
Was This Post Helpful? 0
  • +
  • -

#29 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Posted 07 April 2010 - 06:28 AM

I don't really understand what your asking.
If this is actually the kind of code your using then none of this should work. What your doing is incorrect. In a HTML document all of the tags should be lowercase. Your code should look like this:
<html>
<head>
<meta content="text/html"; charset=utf-8" http-equiv=Content-Type>
<meta name=GENERATOR content="MSHTML 8.00.7600.16535">
</head>
<body>
<strong>this </strong>is <u>test</u>
</body>
</html>

When you post a question on here you should use correct English so we may understand.
You should have posted this in the HTML section of the website. This has nothing to do with the tutorial.

This post has been edited by VB.Terry: 07 April 2010 - 06:30 AM

Was This Post Helpful? 0
  • +
  • -

#30 Guest_Scotty G*


Reputation:

Posted 09 April 2010 - 01:17 PM

Hello, I'm playing around with this editor and I love the tutorial! The only problem I'm having is when I try to place any starting text in the web form. Every time I do the:

doc.selection.createRange() as IHTMLTxtRange;



vs(2005) gives me the error: Error HRESULT E_FAIL has been returned from a call to a COM component.

Do you have any idea why this is happening?
Was This Post Helpful? 0

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4