I am writing a small editor, based on a WPF (c#) TextBox. For some functionality the method getRectFromCharacterIndex(), which is only implemented in the TextBox-class is necessary. Furthermore I've got to do some syntax-highlighting in my program. Normally this is easy to handle in a TextBlock or a RichTextBox. Unfortunately these two Controls don't include Methods like the one mentioned above. Has anyone an idea, how to format and/or color single Characters in a normal TextBox with a small workaround?
Thank you very much for your answers!
I did the same effort in the past and I decided to move to this: http://wiki.sharpdevelop.net/AvalonEdit.ashx almost all the work you need is done here.
Related
I'm currently developing an IDE and Im working on Code-Folding codes now .
I'm thinking to use a TreeView as for it has a collapse and expand property but i dunno/not sure how can I implement it on RichTextBox .
Even an Initial Code showing if interaction within RichTextBox and TreeView will be much appreciated .
like:
{
}
then RichTextBox will have a line indicating till where to collapse .
Thanks a lot in advance!
It doesn't seem feasible to include a TreeView inside a RichTextBox. From my experience, building something atop the RTB is quite problematic and doesn't render the desired result without having quite a lot of quirks.
I suggest taking a look at the Fast-Colored-TextBox:
http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Or possibly building a similar control from scratch (if you too suffer from NIH) instead of attempting to extend the RTB.
If you really need your own code editor you should really think about taking Avalon Edit. It is able to rebuilt an Visual Studio Editor. So it has all you feature you need (and more).
I know it is a WPF component and not winforms. But it is quite easy to host a WPF control within winforms. So better take this route, cause trying to interweave a tree view with a rich text box will never match exactly what you like (just think about finding out the pixel size of a textline if you are using different fonts or how to determine line wrapping).
Reading lots of characters and updating a textbox was suggested to me when I created this question, and it was exactly what I was looking for (couldn't find it by just searching). However a couple of points need clarifying.
I am looking to upgrade to a ListBox or even RichTextBox. For now I want to be able to replace as little of the onscreen (and off, as an added bonus) text as possible.
In the first link Guffa wrote:
If the data is line based, use a list instead of a text box, so that you only have to update the last line when you add a character.
I have a split pane where updates to one TextBox are translated and shown on the other side, and vice-versa. I've briefly toyed with a ListBox but it doesn't provide the intrinsic text-editing funcionality of a TextBox so I went back.
What component should I be using? I wouldn't have thought that with all of .NET available I should have to consider Win32.
Ok, no one else has offered an answer so I will propose a solution which is the last one open to me short of refactoring back to Win32 API calls.
The solution is to use two textboxes. Instead of replacing the text element of the on-screen one you replace that of its dupe, which at the time is hidden, you then toggle the visible flags of both.
I'll let you know how it goes but it is major work for not much advantage, I'll prolly just live with a bit of flicker for now.
I am writing text editor in c# winforms and I want it to Highlight keywords.
Now richtextbox is to slow for opening big files so I am using textbox, but textbox doesn't have a property for setting the color of a selected text.
I tried to inherit from textbox and override OnPaint method but it doesn't seem to work.
I found this code and it looks great but I have no idea how to work with it.
Anyone have a solution?
I'd follow one of the following paths:
Go purchase a ready-made text editor component with the desired functionality.
Write a custom control from scratch.
The standard controls you mentioned were not designed for such advanced scenarios which require a much more elaborate processing of the content being edited.
Have you heard of Scintilla? check here or here
I'm tinkering with writing a simple text-based role-playing game. I would like to use WinForms, and utilize WinForm controls for the UI and simple text for the output. The catch is, I would like to have complete control over the formatting of the individual text - some words being different colors, etc. A simple console control would suffice, as that would provide control over text colors, but it would be nice to also be able to change style, font and size.
Less important: it would be nice to have complete control over where text appears in the control through a coordinate system, as with DOS windows of old.
I'd appreciate suggestions on the best method of implementing this. Perhaps there is a better method I had not considered for rendering the output of a text-based game.
Hmm... maybe you could use or adapt a RichTextBox or a WebBrowser control for this purpose?
You have complete control by overriding the OnPaint() method. Use TextRenderer.DrawText() to get it exactly the way you want it.
Is there a TextBox-like WinForms control that can show a large amount of text (hundreds of megabytes) in read-only mode? Of course it should work without loading the whole file into memory at once.
I'm trying to implement this myself, using a standard TextBox, processing scroll and keyboard events and reading the amount of text necessary to fill the visible "window". But it's still quite buggy, and I'm feeling that I'm reinventing the wheel.
Loading "hundreds of megabytes" of text into a control sounds like a very, very bad idea memory/performance wise; it will likely crash your program. Anyway, how are you going to read all those millions of lines? Do you really need the whole text in there all the time? Mabye it would be better if you had a buffer and loaded small amounts of text into a RichTextBox and when you reach the end (or even near the end), simply load up the next 100 (or any other amount) of lines. Or, if you are searching for something, search for your keywords and put the relevant text in the RichTextBox. It really depends on what you are planning to do.
I think you got best chances by using Scintilla or its wrapper Scintilla.Net. I think it doesn't it job that perfect, but it makes it much better than TextBox or RichtTextBox.
I've no knowledge of such a control (RichTextBox is slow when you put a single wikipedia page into it, so I'm quite sure he loads everything into memory).
My experience with the winforms is that you often need to customize defaults controls to obtain the behavior you want, even when it seems trivial (nullable DateTime anyone ?). On the other hand, they do offer a good base to add one or two simple behaviors quickly without having to do all by yourself.
I've been using winforms controls for several months and often ended up implementing specific (some trivial, others complex) behaviors in my own controls.
There is no such control from what I know. Long time ago I have written similar control but it is for Delphi, but the principles are the same (read limited block of data and render it). So if you decided to implement it by yourself, then move away from TextBox control, it is not well suitable for such needs. I believe you should create new Control descendant with all custom painting. It is not very easy, but it is the only correct way.
Display the text in parts.....10.000 characters in each text box....i recently discovered thet if you make the textbox bigger the program will run faster when editing the text or scrolling...