Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF VS2010 RichTextBox
I'm trying to write a special-purpose text editor program in WPF (C# VS 2010 .NET 4.0). The documents this program will be used to create are of a very specific format, and I'll need fairly precise control over things like margins, paragraph indention, and justification based on this format. Open source or free would be best.
 
(I'm trying to automate something that's been done on typewriters for decades. MS Word would work, but the user would want to create several styles for the various types of paragraphs and then constantly flip back and forth between them as he entered text.)
 
I've read up a bit on RichTextBox and AvalonEdit; both of these seem to have tons of features that are way beyond my requirements (syntax highlighting, code folding, etc.) though they're both missing some of the basic features I really need.
 
Can anyone recommend either of those, or suggest a better starting point for the control I need? Here are my requirements:
 
- Single fixed-pitch font with only bold, underline, and italics
- Variable left/right margins and automatic word wrap while maintaining indention
- Support for keystroke events including [enter] and [tab]
- Ability to programmatically move the text caret to arbitrary locations
- Handles large documents (say around 10MB of text) quickly
- A view mode showing page separators (like MS Word, showing the bottom of one page and top of the next page, or Adobe Reader with "Enable Scrolling" and "Show Gaps Between Pages"; I say "full-time" because I don't want to have to go into "print preview" mode to see the page breaks
- Left, center, and right-justify
- Real-time and whole-document spell check
- Word-like ruler showing margins and indent level
- Save to HTML or preferably XML format
- Export or print to PDF format
- The usual copy/cut/paste stuff
- Undo/Redo
- Search and replace
 
Additional "nice to have" features are:
 
- Support for text format templates
- Zoom (not to increase font size, but to increase the size of the page display)
- Split window
- Revision marks
 
I realize I'll have to write code to support some of these features, but anything that would help me get started and have some of these features already implemented is what I'm looking for.
 
Thanks!
Posted 9-Jan-13 17:54pm
Edited 9-Jan-13 18:12pm
v2
Comments
Sergey Alexandrovich Kryukov at 10-Jan-13 0:09am
   
This is a reasonably posed important problem; I even voted 4 for the question (which really rarely happens these days), but just one trouble is: this is not really a question (there is no even a question mark).
 
This is just a Questions & Answers forum, so you post is somewhat out of its format...
 
I'm one of those freaks who use my own text editor in most cases, but how could I possibly help you? By writing yet another editor? Or by writing a whole book on writing editors? In principle, I could, as I know nearly everything what's involved, but... this is too much work, and not the most interesting and potentially fruitful in the world...
 
—SA
J. Elliott at 10-Jan-13 0:13am
   
Sorry... CodeProject seems to have changed its format since I last posted here. There used to be programming forums where this would be more appropriate, but I can't find them tonight!
 
My question is (para 4 above): Can anyone recommend either of those, or suggest a better starting point for the control I need?
 
This isn't intended to be yet another general-purpose text editor, but is very specific in its purpose. There is quite a market for such a program in the target demographic I'm aiming this project towards, if it's done right. I just don't want to reinvent the wheel is all, if such a control already exists that can handle most of the project's requirements.
Sandeep Mewara at 10-Jan-13 0:33am
   
If you are looking for C# forum: http://www.codeproject.com/Forums/1649/Csharp.aspx
J. Elliott at 10-Jan-13 0:21am
   
And thanks for the 4 vote! Much appreciated.
Sergey Alexandrovich Kryukov at 10-Jan-13 1:37am
   
I almost put a big answer (well, may be not a real one, but a number of notes), but the CodeProject script hangs on it, so I cannot retrieve already written text at this moment.
—SA
Sergey Alexandrovich Kryukov at 10-Jan-13 9:37am
   
Done...
Sergey Alexandrovich Kryukov at 10-Jan-13 18:28pm
   
[OP commented:]
 
Thanks Sergey and Espen! (There doesn't seem to be a way for me to answer your specific posts, so I'm writing in the "Add your solution here" block at the bottom of the page.)

That was exactly the kind of advice I was looking for, and the links are a big help. I'll continue checking into existing WPF controls and classes if I end up rolling my own, but I'll also check out the DevExpress controls. My group was originally sold on writing this all from scratch, but if we can spend a little money and get a presumably well-tested and robust control that does most of what we need (with support), that makes sense too.

The project is a script writing program, for TV/movie/book scripts. The required text format is very specific and industry-standard, and it dictates the font, line spacing, margins, and such. The execs who receive these scripts expect PDF format, and they almost exclusively run Macs. I've not heard of an XPS reader for the Mac, but we wouldn't want to impose that requirement anyway as those execs aren't really our target audience.

Of course I'll need caret position indication, and probably keyboard macros too. The thing about justification is that some of the lines in the predetermined format call for left justification, some lines have to be centered, and one type of line has to be justified up against the right margin. Just one font: Courier New 12 (with optional bold/underline/italics). I get your point about pasting in text that uses another font, so I'll probably need something to intercept and modify that text.

Again, thanks for the great tips!
Sergey Alexandrovich Kryukov at 10-Jan-13 18:29pm
   
[Espen replied]
 
If you press the "Have a Question or Comment?" button below each solution we will get notified. I've been using the components from DevExpress for several years, they certainly provide good value for the money. As I subscribe to the "Universal" edition of Dxperience I also get the full sourcecode for the components.
Sergey Alexandrovich Kryukov at 10-Jan-13 18:32pm
   
Hi J.,
 
As we both noticed your message (just be a chance, in fact), I removed the "Solution" and put a copy here. Please understand that we could not get notification of that post; but we get notification related to our posts, so you could notify us by commenting on our comment.
 
Thank you for your feedback,
 
Good luck, call again,
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all, please see my comment to the question. It's long enough to continue in a separate post, but first of all because if has to be some kind of the answer.
 
From my explanations of this situation, you probably should have understood by now, that it's very likely that you are the one who should do all this work. Can you tell me why not?
 
There is nothing special in your requirements, nothing very new. The most difficult requirement will be quick load of 10 M of text. Actually, there is one peculiarity of WPF, due to which my incomplete WPF editor (not the one I use on regular basis), actually loads this very quickly, but… when you scroll it, say, to the middle, it becomes slow. This is because WPF has separate UI and rendering threads.
 
You missed some important features, such as indication of the position of the caret (simple in WPF) and such thing as macro, at least keyboard macro (I implemented them, but, unfortunately, not completely without P/Invoke; something important is still missing from WPF).
 
Why PDF? Not XPS (which I think is better then damn PDF in a number of aspects)?
 
Also, your centering, alignment, etc. does not look adequate. It should either be missing, or you would go to the other end, implementation of features close to Microsoft Word or rather LibreOffice (http://en.wikipedia.org/wiki/LibreOffice[^]).
 
If you want to go take this route, why not considering System.Windows.Documents.FlowDocument? Please see:
http://msdn.microsoft.com/en-us/library/aa970909.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx[^].
 
The contradiction, again, is that you want to show different paragraph alignment but, as I can understand from your list, not different fonts (I refer to the first item of your list). This is not in line with any of the components you might use as a base class. Or you would need to start from very low level, from Control class with custom rendering. But imagine what happens if you use Rich Text of FlowDocument as the base. You can enforce one uniform font throughout the document. So far so good. But here is the catch: you will have also suppress the clipboard Paste and replace it with your own. Do you see why? Otherwise an attempt to Paste will insert a text fragment with source formatting, something your document is not suppose to render. Not that this is too difficult; it is rather unpleasant.
 
What else? XML. There is no "just XML". It could be this: http://en.wikipedia.org/wiki/OpenDocument[^].
 
PDF export? Usually, people use iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^],
http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial[^].
 
Again, consider XPS:
http://en.wikipedia.org/wiki/Open_XML_Paper_Specification[^].
 
This is a standard thing:
http://www.ecma-international.org/publications/standards/Ecma-388.htm[^].
 
By the way, FlowDocument can be exported as XPS.
 
I've mentioned only a small part of your list. I guess, the main problem will be the choice. You will deal with the temptation to start everything from scratch (in the sense I described above) and the lacks of helping features in existing text-editor-like components and related brick wall. Well, several brick walls… Smile | :)
 
—SA
  Permalink  
Comments
Espen Harlinn at 10-Jan-13 10:05am
   
A number of good points :-D
Sergey Alexandrovich Kryukov at 10-Jan-13 10:08am
   
Thank you, Espen.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you don't mind paying for a professional control, have a look at: DXRichEdit[^] - it has most of the features you require.
 
You can use the XtraPrinting[^] library to export to PDF
 
Best regards
Espen Harlinn
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 10-Jan-13 10:11am
   
Interesting, a 5. :-)
 
To me, you are a very much of a 3rd-party person. Do you see what I mean? You often bring something not widely known but interesting, all from 3rd parties. What, always looking around for a wide range of products, on a very regular basis?
 
By the way, thank you very much again for giving me a link to ILSpy. So far, works like a charm. And it was built at once (except some test projects); all source code is put together, not a single bit of binary code without source. Even a bit more convenient than Reflector. The only benefit of Reflector I see so far is the disassembly into Delphi Pascal and F#...
 
—SA
Espen Harlinn at 10-Jan-13 18:08pm
   
I've been subscribing to the universal edition of Dxperience for some years now, it's certainly a well designed set of components.
 
ILSpy is an impressive tool, and I'm glad you found some good use for it :-D
Sergey Alexandrovich Kryukov at 10-Jan-13 18:28pm
   
:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 Sergey Alexandrovich Kryukov 219
3 Peter Leow 190
4 CPallini 189
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 5,022
2 Maciej Los 3,269
3 Peter Leow 3,164
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100