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
Related
I have a pretty straightforward WPF application, but with a lot of forms, nearly 80, spread out to UserCcontrol xaml files and navigated with TabControl on a main Window file. Some of those forms contain a lot of data, but basically everything is broken down to TextBlock, TextBox, Label, Grid, RadioButton and ComboBox controls.
I am done with everything, but there is a requirement that everything at the end should be exported to a file - either PDF, or Word. Is there an easy way to do that? I don't have a requirement to have the same style and formatting. I only need the text - question and given answer, either text, or chosen option.
I have searched the web and saw many solutions, but PdfSharp was the best, I believe. However, I do have a lot of forms and it would be an overkill to map every single user control in a loop or something, to write to file. Creating a bitmap or an image and print to file would not help, since I have text boxes with scrolling and the whole text would not be visible in such cases.
What best would work for me would be a library that accepts, let's say, a user control and then prints its content on a page(s) of a file. Once again - I don't need any styling or formatting or images, just text.
Here is a small example of what one of the forms looks like, just to give you an idea:
Thank you in advance!
I've looked for similar tools and there isn't much out there, especially if you are looking for something open-source.
The most straightforward approach will be using tools found in the System.Windows.Automation namespace. That should help you write some helper functions that can capture text from all of the elements in your controls.
This link should be helpful:
https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/obtain-text-attributes-using-ui-automation
I had some little experience in coding, but I am absolute beginner in C#. In my program I want to make the text visible in form, sort of like in HxD program. I don't want it to be standard editable text, but a monospaced text which can be selected, and if selected there would be yellowish (but with no border) background in back of it, I have no idea how to do this, if even possible with standard controls. How can I implement this? Do I need to use some external library? I want also to mention that I want spaces between characters and lines to be configurable.
I am using Visual Studio C# 2015.
Here is mock-up:
I've done similar before using a RichTextBox that wasn't editable by users. It has more functions for manipulating just part of the string than TextBox does.
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).
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.
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.