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.
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 have an application on windows with multiline text field on it. I need a way to draw lines on that text field, so you could see both, the letters typed and those lines. I need to do this with C#, but I can use .dll's written in C++.
I've heard something about subclassing where I could overtake render function from a window and adjust something to it, how do I do that with C#?
Or maybe there are simplier ways than that? Please share.
In .NET Framework, you may use WPF and write user control with Canvas and TextBox overlaying - and then make such operations with Dependency Properties tracking
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 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.