![]() - // - // font size should be translate to // html size (Approximately) int fsize = yHeight / ( 20 * 5) - // - // new font format ? if ((strFont != strfname) || (crFont != cf.crTextColor) || String strfname = new string(cf.szFaceName) ![]() This is done by using an internal structure cMyREFormat that stores the related information such as the position and the tag that should be there in that place: I perform formatting analysis one by one on the characters in the control and extract the information about its style, if at any moment the character format or the paragraph format is changed, I add an HTML tag to the raw text. To get the HTML content from the control I use the following approach: character by character ( If someone knows an alternative method, please let me know). - Getting HTML content from the control new paragraph requires to reset alignment String strAux = strData // use another copy StrData = strData.Replace( " '", " \"" " ) Please, see the source code for more details: To apply formatting through PARAFORMAT and CHARFORMAT, I use properties (a good tip taken from the Internet). StrData = strHTML.Substring(nEnd + 1, nStart2 - nEnd - 1) Math.Min(LF_FACESIZE - 1, strFont.Length)) Ĭf.dwMask |= CFM_COLOR | CFM_SIZE | CFM_FACE String strCr = strTag.Substring(nColor + 8,ĬrFont = int.Parse(strTag.Substring(nColor + 7, If (strTag.Substring(nColor + 7, 1) = "# " ) Int nColorEnd = strTag.IndexOf("\ " " ", nColor + 7) YHeight = int.Parse(strTag.Substring(nSize + 6, Int nSizeEnd = strTag.IndexOf("\ " " ", nSize + 6) StrTag.Substring(nFace + 6, nFaceEnd - nFace - 6) Int nFaceEnd = strTag.IndexOf( " \"" ", nFace + 6) String strTag = strHTML.Substring(nStart,Ĭf.dwMask |= CFM_UNDERLINE | CFM_UNDERLINETYPE Įlse if (strTag.IndexOf( " align=\"right\"") > 0)Įlse if (strTag.IndexOf( " align=\"center\"") > 0) ok, get tag value int nEnd = strHTML.IndexOf( ' >', nStart) tag is not the first character, so // we need to add text to control and continue // looking for tags at the begining of the text looking for start tags int nStart = strHTML.IndexOf( ' = 0) Please see the source code for more details. There are many Internet sites and blogs that use this approach. This should be more efficient than calling the native RichTextBox methods because I believe every call to a RichTextBox method makes a system SendMessage call, and I can use the PARAFORMAT and CHARFORMAT structures to get more information about the RichTextBox content with only one call at a time. I use Win32 APIs to get character and paragraph formatting structures. But, the control can be extended according to your needs to include other features and HTML tags handlers. It is named " HTML lite" because I don't handle all the HTML tags, only a small subset of them with some constraints. Well, I decided to implement a successful solution to save and load "HTML lite" text into the RichTextBox control. I also wanted a method for inserting images and ActiveX controls into the RichTextBox control, please see my article: Inserting images into a RichTextBox control (the OLE way). NET RichTextBox control only allows you to save and load files using RTF codes or plain text files (oh! my God). When I was working on a chat application I found that the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |