I am working in a RichTextBox and I need to highlight certain text as incorrect (by my own checking). I have crawled all over the web trying to find something- preferably a package or library that I can use to achieve this...
I'm very surprised that this format isn't a default style in the RTB font style settings...
Related
I have a lot of formatted code snippets saved in an XML file.
On request I load them and set as Rtf in a RichTextBox:
string cscode = #"{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fprq1\fcharset0 Courier New;}{\f1\fnil\fcharset0..." etc.
rtb_cs.Rtf = cscode;
The code snippets are copy-pasted from the Visual Studio, so the text is colored differently.
Different Visual Studios are using different Fonts for the text.
Is there a way to change the Font but keep the colors?
I've tried to set the Font property of the RichTextBox, but this also resets the colors.
//This changes colors as well
rtb_cs.Font = new Font(FontFamily.GenericSansSerif, 10);
Take a look at LarsTech's solution here:
Changing font for richtextbox without losing formatting
It works for other settings too.
How do I add "styled" (bold, italic etc.) tips in C#? Or is there any way to do this?
PS: That code on image doesn't work.
The "styling" in your image is not part of the C# specification. It's just your editor (Sublime?) that does some basic parsing, and sets the text color of items it recognizes.
You can see for yourself if you open your so-called "styled" source code in a plain text editor such as TextEdit or Notepad. Even if you can see colors again, they are assigned by that software in turn.
So, I have text entered in textbox, which I need to show as preview in label. Problem is, it has specific formatting, so #A is trigger for red color, and text is red colored util some other text color sign is inserted (like we at some point insert #B and text is green from that point, and so on).
That wouldn't be big problem if there weren't two problems:
Obviously this is web application, and although is written in C#, many things that can be done on windows forms, can't be done here.
Bigger problem, that I can't solve is that I also have signs for text background and for text hight (which I would solve in classes).
font color red_____________green___________blue__________
font bacgr. black_________________________________red_____
font hight normal_________________double_________________
I hope you get it, I have three groups of parameters (font color, background color, and text hight) and parameter from one group should change one property, and others should stay.
This is sure complicated, but at least I would need idea how to make that for example #A triggers that color of text in Label becomes red, and that #A is deleted, and when after that is for example #B, at that point text becomes green, and so on.
Have in mind that this is ASP.NET, so many C# features are not available.
The simplest way to accomplish this would be parse the string for your tags and replace them with equivalent HTML/CSS tags (<span class="red">) that implement the formatting you want.
I would like to know whether it's possible to display formatted (like bold, font size) text using sendkeys.sendwait() method.
Note: The indented text string is already formatted. I need to way to print them on the application.
Is there anything I can do with clipboard?
As Robert Harvey stated, you would have to send the keys that trigger the formatting. If you are working with a word processor that allows bold, italics, underline, you could achieve the following like this:
SendKeys.SendWait("^BThis is bold Text!^B^IThis is italics!^I^UThis is underlined!");
... assuming that CTRL+B is bold, CTRL+I is italics, and CTRL+U is underline.
Question A.
Given
A string in rich text format that may have paragraph, tabs, space, line break, indentation, (or even image?)
A width for the word wrapping rich text control/editor
How do I know the height of the content after it have performed all the word wrapping?
Is there something like
int MeasureRichTextHeightAfterWordWrap(string aRichTextContent, int aWidth)?
Otherwise how does those rich text control know how much to autosize?
Do I have to actually place the content on a dummy rich text control, set it's width and get its height with GetPositionFromCharIndex(TextLength-1) afterwards?
Although this does work, it seems to be "wasteful"
Question B.
If I draw plain text onto a plain text memo/control/editor,
and manually draw string with manually calculated indentations, breaks, word wrappings to pretend the RTF.
Is it easier or harder?
Edited to make it look clearer
and sorry if my English looks like a student cause it's not my native language.
Sorry about my bad first attempt at an answer. I DID find an answer for measuring inside a RichTextBox. Apparently you have to use Win32 GDI API calls.
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2004-09/0574.html
I found this by changing my search after running across this nugget, which explains why there's not a pure .NET way to do it:
http://www.developmentnow.com/g/38_2005_10_0_0_626243/I-dont-believe-this-code-gives-the-correct-RichTextBox-string-size.htm