Background
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. - Independent.
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 button
/toolstripbutton
or menu item on the form, select a button
, at PropertyGrid
, you can see a property item name "at myCommandControler
's 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;
myCommandControler.Start();
}
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 "InsertString
":
[WriterCommandDescription("InsertString")]
protected void InsertString(object sender, WriterCommandEventArgs args)
{
if (args.Mode == WriterCommandEventMode.QueryState)
{
args.Enabled = args.DocumentControler != null
&& args.DocumentControler.CanInsertElementAtCurrentPosition(
typeof(DomCharElement));
}
else if (args.Mode == WriterCommandEventMode.Invoke)
{
args.Result = 0;
InsertStringCommandParameter parameter = null;
if (args.Parameter is InsertStringCommandParameter)
{
parameter = (InsertStringCommandParameter)args.Parameter;
}
else
{
parameter = new InsertStringCommandParameter();
if (args.Parameter != null)
{
parameter.Text = Convert.ToString(args.Parameter);
}
}
if (args.ShowUI)
{
using (dlgInputString dlg = new dlgInputString())
{
dlg.InputText = parameter.Text;
if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
{
parameter.Text = dlg.InputText;
}
else
{
return;
}
}
}
if (string.IsNullOrEmpty(parameter.Text) == false)
{
args.Result = args.DocumentControler.InsertString(parameter.Text);
}
}
}
In this code, the "QueryState
" party detects whether the command is Enable
currently. System
will call this party to set Button
/MenuItem.Enable =true
or false
. The "Invoke
" party is defined in the body of command.
File Format
Currently, 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.
Deploy
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.
Support
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].
Compatibility Warning
In this version, the width of whitespace is too small. In the future, the width of whitespace maybe increase, this will change document layout.
Route Map
This is the route map:
- For programmer, currently
CSWriter
supports WinForm.NET, Console, Windows Service. CSWriter
providers a type CSWriterControl
base System.Windows.Forms.UserControl
, Paint
document content by itself, handles mouse and keyboard event by itself, without any third part component. - COM-Interop,
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.
Inside CSharpWriter
DOM
The core of CSWriter
. Dom description any details of document. Every part of document has map to a class instance. Programmer can new or delete Dom elements, modify element's property, those can update document view, just like JavaScript update HTML view by modify HTML DOM. DOM also is expendable, in the future, it will add new type element class, support new behavior. Create an unlimited cswriter
.
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 tree.[Document]
is the single enterpoint to access DOM tree.You can insert/delete element in the tree, and the system can update view quickly, just like JavaScript access HTMLDom.
License
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.