Many people use standard
RichTextBox control to handle RTF style text, but
RichTextBox control has lots limited. For example, it cannot be used in NO-GUI application, RTF file format is hard to parse, hard to change party of document content by programming.
What is CSharpWriter
CSharpWriter (short name
CSWriter) is a new RTF style document process engine without
RichTextBox control. it is more powerful than
RichTextBox. We hope it can replace OpenOffice in .NET World. It supports:
- RTF style document content like text color, back color, font.
- DOM, you can create document in memory without creating GUI control. So
CSWriter can be used in console /ASP.NET application.
CSWriter is independent to other components. It draws all content and GUI using
system.drawing.graphics, handles mouse and keyboard events by itself. You can use it without technology limited.
- Easy to use. You can place a control on your Winform. It provides thousands OOP APIs.
- Lite weight control.
CSWriter is implemented from
System.Windows.Forms.UserControl. It runs in application UI thread, use less memory. You can catch any unhandled exception.
- Support XML format. The result file is more easy to parse than RTF format. Use DOM, you can create your owner file format.
CSWriter is developing. If you have any idea about
CSWriter, you can visit the site [https://github.com/dcsoft-yyf/CSharpWriter].
How to Use CSharpWriter in WinForm.NET
Just like other winform control, you can use
CSWriter easily. In VS.NET IDE, open winform designer, at toolbox left side, choose "choose items..." . and select file DCSoft.CSharpWriter.dll, then you can see
CSWriterControl on toolbox, just like the following:
You can drag a
CSWriterControl and a
CSWriterCommandControler to the form, change its name as '
myEditControl' and '
myCommandControler'. Next, you can add some
toolstripbutton or menu item on the form, select a
PropertyGrid, you can see a property item name "at
CommandName", just like the following:
Click button at the end, then show a dialog like this:
And you can select a command with binding to the button. Then you design a form like this:
Open the source editor, at the
form_load event source code, add the following code:
private void frmTextUseCommand_Load(object sender, EventArgs e)
myEditControl.CommandControler = myCommandControler;
After do this, you can run application, click button or menu item to use
CSWriter. Look, it is so easy.
CSWriter supports a lot of commands. You can open a file by code
myEditControl.ExecuteCommand("FileOpen", true, null), save a file by code
myEditControl.ExecuteCommand("FileSaveAs", true,null), insert a
string at current position by code
myEditControl.ExecuteCommand("InsertString",false,"Some text content") .
Those commands defined in WriterCommandModuleBrowse.cs, WriterCommandModuleEdit.cs, WriterCommandModuleFile.cs, WriterCommandModuleFormat.cs, WriterCommandModuleInsert.cs, WriterCommandModuleSecurity.cs, WriterCommandModuleTools.cs in directory "CSharpWriter\Commands". You can add your owner command in those files. For example, this code defines command "
protected void InsertString(object sender, WriterCommandEventArgs args)
if (args.Mode == WriterCommandEventMode.QueryState)
args.Enabled = args.DocumentControler != null
else if (args.Mode == WriterCommandEventMode.Invoke)
args.Result = 0;
InsertStringCommandParameter parameter = null;
if (args.Parameter is InsertStringCommandParameter)
parameter = (InsertStringCommandParameter)args.Parameter;
parameter = new InsertStringCommandParameter();
if (args.Parameter != null)
parameter.Text = Convert.ToString(args.Parameter);
using (dlgInputString dlg = new dlgInputString())
dlg.InputText = parameter.Text;
if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
parameter.Text = dlg.InputText;
if (string.IsNullOrEmpty(parameter.Text) == false)
args.Result = args.DocumentControler.InsertString(parameter.Text);
In this code, the "
QueryState" party detects whether the command is
System will call this party to set
MenuItem.Enable =true or
false. The "
Invoke" party is defined in the body of command.
CSWriter save load or save XML file format. In the future, it will support RTF, HTML(MHT), PDF, BMP, ODF(Open document format) file format and you can add your owner file format.
CSWriter is a lite GUI Control component. All parts are included in single file "DCSoft.CSharpWriter.dll". Independent any third part component. It runs on MS.NET framework 2.0 SP2 or later. Notice, you must add SP2 because
CSWriterControl use property "
CanEnableIme" which is defined in SP2 (not defined in .NET2.0 without SP2).
When you need update
CSWriter, overwrite DLL file , and re-compile your source code and finish.
CSWriter provides technology support. If you have some question or idea, you can leave a message below or visit site[https://github.com/dcsoft-yyf/CSharpWriter].
In this version, the width of whitespace is too small. In the future, the width of whitespace maybe increase, this will change document layout.
This is the route map:
- For programmer, currently
CSWriter supports WinForm.NET, Console, Windows Service.
CSWriter providers a type
Paint document content by itself, handles mouse and keyboard event by itself, without any third part component.
CSWriter will support COM-Interop using
System.Runtime.InteropServices, it will support COM-base developing, such as VB6, VC6, PowerBuidler, Delphi7(XE) or host in IE as ActiveControl.
- For Web programmer, in the future,
CSWriter will support WEB developing, such as ASP.NET WebForm/MVC and ASP.NET Core. and also can work with JAVA/PHP/Node.js application. It will support web browser compatibility, etc. IE/Edge/Chrome/Safari/Firefox. One document in different web browsers, has the same view, same content layout and same print result.
- For GUI Operator,
CSWriter just like a MS Word style. You can type any
char, support English, Arabic, Tibetan.You can change text font, color, backcolor, paragraph format. In the future, it will support table.
- Performance. We are working hard to performance optimization. In the future, you can load document with 1000 pages completed no more than 10 seconds. Handle table with 1000 rows smooth.
The core of
This is element implement tree in DOM:
DOM defines a set of classes, just like HTML DOM, each type of class maps to a type content in document. For example,
DomDocument class maps to the total document. It is the primary enterpoint for programming;
DomImageElement maps to a image in document,
DomCharElement maps to a character in document.
This is DOM element reference tree:
CSWriter builds a DOM tree in memory, every document element instance is placed in the
CSWriter uses LGPL-2.1 License. If you want to change License type and use it in business unlimited, you can contact me by leaving a comment below.