http://www.codeproject.com/Articles/17307/HTMLTextBoxDownload source and sample - 63 Kb Introduction This Rich Text Editor-style control comes from a reference of the "Body Editor" in "New Message" dialog of Outlook Express. As we know, although aRichTextBoxcontrol is already provided within .NET Framework by Microsoft to display rich text for users, it still lacks in some real Rich Editing works which are extremely desirable. As a consequence, this control is right for the real editing work. InsideHTMLTextBox As a subclass ofUserControl,HTMLTextBoxmainly consists of two parts: oneToolBarand oneWebBrowsercontrol. How to enable the WebBrowser to be editable? TheWebBrowserwill enter "Edit Mode" after performing the following code. Collapse|Copy Code webBrowserBody.Document.ExecCommand("EditMode", false, null); How to overstrike your font Perform the following code to enable the BOLD font on the selected characters. Collapse|Copy Code webBrowserBody.Document.ExecCommand("Bold", false, null); All the operations in this control are executed by invoking the functionExecCommandofWebBrowser.Document. For detailed info aboutExecCommand, please refer to Microsoft MSDN. PS: As announced by Microsoft inCommand Identifiers, some of the Commands are mentioned to be no more applicable, however, they still work well. Please do not rely it 100 percent, just give a shot! About Optional Fonts Collapse|Copy Code foreach (FontFamily family in FontFamily.Families) { toolStripComboBoxName.Items.Add(family.Name); } All the optional fonts in this control are retrieved by means of the code above. About Font Size InHTMLpage, seven types of font size are applicable (from 1 to 7). And the relationship between theHTMLfont size and the common font size is summarized in the following table: HTMLFont SizeCommon Font Size18210312414518624736 To avoid confusion, the Common Font Size will display for users instead of theHTMLFont Size. How to useHTMLTextBox As aUserControl,HTMLTextBoxis very convenient for your use. And I do not override or expose too many properties or methods. By far, it just has two public properties":TextandImages. If you want more, you are free to add them by yourself for any purpose. Text: to set or get more meaningful text, it is overridden. get: return the entireHTMLcontent including and etc.set: set any text value and display them in this control, meanwhile, the "/r/n" will be automatically translated into
. Images: to get the unique directories of all the attached images NOTE: the COM object "MicrosoftHTMLObject Library" will be referenced byHTMLTextBox. About Sample Email Sender Example Before running Sample, the following code needs to be changed accordingly. In lines 23 - 26 inMailSender.cs Collapse|Copy Code string host = "192.168.22.12"; int port = 25; string userid = "jay.liu"; string password = "1111"; Loathsome BUG The image inserted into the edit body cannot be resized, and no exception will be thrown. For now, I have no idea about the reason or solution. History First Version (1/22/2007). 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 foundhere
posted on 2012-09-06 10:13  懒懒的呐喊  阅读(160)  评论(0编辑  收藏  举报