質問

I'm in the process of writing a small text-editor that is supposed to have very basic formatting capabilities, nothing fancy, yet more complex than what RichTextBox can provide (including a 'page' display functionality).

However, last time I wrote any text editors was with WinAPI in C for Windows 3.1. I have no idea on how to approach this with .NET. The furthers I've gotten until a blank is using TextRenderer.DrawText() to output the text I have into a rectangle... but something tells me that's not the way to go in this case, because I've thought all along that for one, I will want the background text in XML format... and while I can break up the paragraphs with tags, I have no clue how to do the formatting, such as or a different font family, so it probably need to be approached a little differently. Probably each word separately. Do I have to keep each word in an array (with respecting xml tags) and draw it as a separate control keeping its positions in an array as well? That sounds like an awful lot of memory and drawing power if we're talking about hundreds of thousands of words in one file (it's a possibility, although I highly doubt one file would extend beyond 20000 words, however anything's possible and together with the word's points (formatting is only available to full words, so no worry about that) it may grow pretty big with memory usage, something that I don't particulary prefer to happen.

So... what I'm looking for is a few hints and tips (I can't use Tx Text Editor, DevExpress or Telerik's RichTextEditors for a good reason plus their price). on the most correct way to build a 'word processor' that is well extendable with C#.NET as it's the one thing I have so far never had to stick my nose into.

Basically:

1) Best way to draw text into a custom control. How should I keep my text? I will probably use the base Text property for pre-formatting stage when I load the files. Or perhaps I'll extend it with my custom XML class? Should I keep words in order in position and joining them by hand when backspace is used? Etc etc.

2) Best way to do selection (probably only one way I presume?), while in WinAPI I could just detect the character under cursor as it was standard text, considering the amount of fonts and the way windows draws the characters I would either have to OCR and then start calculating position... so I presume there's a better way of selecting text?

3) Editing text - which I would assume is simple once I have a cursor position.

Cheers for reading and... hopefully someone comes up with a better solution than my feeble DrawText which... isn't really the solution.

役に立ちましたか?

解決

If you're looking to create a more fully-functional text editor in WPF, you might want to start with this sample and work on from there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top