레이블이 Editor인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Editor인 게시물을 표시합니다. 모든 게시물 표시

2010년 3월 8일 월요일

An extended RichTextBox to save and load "HTML lite" files

http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx






Introduction

When I was working on a chat application I found that the .NET RichTextBox control only allows you to save and load files using RTF codes or plain text files (oh! my God).

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).

Well, I decided to implement a successful solution to save and load "HTML lite" text into the RichTextBox control. It is named "HTML lite" because I don't handle all the HTML tags, only a small subset of them with some constraints. But, the control can be extended according to your needs to include other features and HTML tags handlers.

Background

I use Win32 APIs to get character and paragraph formatting structures. 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. There are many Internet sites and blogs that use this approach.

Word Processing with an Extended Rich Text Box Control

http://www.c-sharpcorner.com/uploadfile/scottlysle/wordprocessor02042007234628pm/wordprocessor.aspx


Introduction: 

This article describes an easy approach to building a simple word processor around an extended version of the Rich Text Box (RTB) control; Microsoft has made available an extended version of the RTB control that greatly eases the requirements for printing the control's text or RTF content. This article and the sample application will use this extended version of the RTF control to demonstrate the following word processor related functions:

  • Opening Text, RTF, HTML, or other text files into a RTB control
  • Saving Text, RTF, HTML, or other text files from an RTB control
  • Implementation of the Page Setup dialog control
  • Implementation of the Print Preview dialog control
  • Implementation of the Print dialog control
  • Setting font properties on selected text or RTF within the RTB control
  • Searching for and highlighting text contained within the RTB control
  • Searching for and replacing text contained within the RTB control
  • Adding Indentation to sections of an RTB's content
  • Adding Bullets to sections of an RTB's content
  • Implementing Undo/Redo within an RTB
  • Implementing Select All, Cut, Copy, and Paste in an RTB control
  • Embedding Images into an RTB control
  • Setting page and font colors
  • Implementing Alignment options in an RTB control

Whilst this project will not lead you to drop MS Word, it is a decent little word processor and to that end, you may find a use for it. I have always kept one of these on hand and have frequently tailored them to do things like provide a custom tool for viewing reports, error logs, and things of that nature when I wanted to integrate that feature into a product so that I could use it in lieu of doing something like shelling out a text file into Notepad. Doing so allows me to control the appearance of the application, the caption in the title bar of the form, etc.

Figure 1:  The Editor Application in Use