Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. RichTextBox.Text is formated in HTML [modified]

RichTextBox.Text is formated in HTML [modified]

Scheduled Pinned Locked Moved C#
htmlquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 1 Offline
    1 Offline
    10102106
    wrote on last edited by
    #1

    Hello, How can I get all contents in RichTextBox and convert it to HTML format My RichTextBox on winform. And I want to get it contents in HTML to sent it to my mail. But it doesn't work properly when I set BodyFormat = HTML. Thank you, ACB -- modified at 12:25 Thursday 26th October, 2006

    ngh

    W E 2 Replies Last reply
    0
    • 1 10102106

      Hello, How can I get all contents in RichTextBox and convert it to HTML format My RichTextBox on winform. And I want to get it contents in HTML to sent it to my mail. But it doesn't work properly when I set BodyFormat = HTML. Thank you, ACB -- modified at 12:25 Thursday 26th October, 2006

      ngh

      W Offline
      W Offline
      Wolf92
      wrote on last edited by
      #2

      You could set it so it can only save as .htm(L)

      1 Reply Last reply
      0
      • 1 10102106

        Hello, How can I get all contents in RichTextBox and convert it to HTML format My RichTextBox on winform. And I want to get it contents in HTML to sent it to my mail. But it doesn't work properly when I set BodyFormat = HTML. Thank you, ACB -- modified at 12:25 Thursday 26th October, 2006

        ngh

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        I've used this in the past:

        public string ToHTML(RichTextBox Box)
        {
        	string sReturn;
        	long lColour;
        	bool bBold;
        	bool bItalic;
        	string sFont;
        	long lSize;
        	long lOldSelStart;
        	long lOldSelLength;
        	long a;
        
        	//Initial box setup
        	{
        		lOldSelStart = Box.SelStart;
        		lOldSelLength = Box.SelLength;
        		Box.SelStart = 0;
        		Box.SelLength = 1;
        	}
        
        	//Initial text
        	sReturn = "";
        
        	//Inital paramaters
        	lColour = Box.SelColor;
        	bBold = Box.SelBold;
        	bItalic = Box.SelItalic;
        	sFont = Box.SelFontName;
        	lSize = Box.SelFontSize;
        
        	//Initial font setup
        	sReturn = sReturn + "";
        
        	//Initial bold setup
        	if (Box.SelBold == true)
        	{
        		sReturn = sReturn + "**";
        	}
        
        	//Initial italic setup
        	if (Box.SelItalic == true)
        	{
        		sReturn = sReturn + "_";
        	}
        
        	//Append new character
        	sReturn = sReturn + Strings.Mid(Box.Text, 1, 1);
        
        	for (a = 2; a <= Strings.Len(Box.Text); a++) {
        		//Set up reading paramater
        		{
        			Box.SelStart = a - 1;
        			Box.SelLength = 1;
        		}
        		//Check for updated font tage
        		if (Box.SelColor != lColour | Box.SelFontName != sFont | Conversion.Int(Box.SelFontSize) != lSize)
        		{
        			sReturn = sReturn + "_****_";
        		}
        		//Check for changed boldness
        		if (Box.SelBold != bBold)
        		{
        			if (Box.SelBold == false)
        			{
        				sReturn = sReturn + "_**_";
        			}
        			else
        			{
        				sReturn = sReturn + "**";
        			}
        		}
        		//Check for changed italics
        		if (Box.SelItalic != bItalic)
        		{
        			if (Box.SelItalic == false)
        			{
        				sReturn = sReturn + "**_**";
        			}
        			else
        			{
        				sReturn = sReturn + "_";
        			}
        		}
        		sReturn = sReturn + Strings.Mid(Box.Text, a, 1);
        		//Update paramaters
        		lColour = Box.SelColor;
        		bBold = Box.SelBold;
        		bItalic = Box.SelItalic;
        		sFont = Box.SelFontName;
        		lSize = Box.SelFontSize;
        	}
        
        	//Check ending bold and italic
        	if (bBold == true) sReturn = sReturn + "_**_"; 
        	if (bItalic == true) sReturn = sReturn + "_"; 
        
        	//Terminate HTML
        	sReturn = sReturn + "";
        
        	//Restore box values
        	{
        		Box.SelStart = lOldSelStart;
        		Box.SelLength = lOldSelLength;
        	}
        	return sReturn;
        	//Return value
        }
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups