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.
Related
I have been trying to find how to change a rich text box into ONE color specifically, not multiple colors in one. Google has been no help, because it assumes I am looking for multiple lines of random colors. I saw nothing here, but I'm sure there is something on here, but I have yet to figure out how to ask the question properly I guess. So I ask it here. How do I do it? My code only displayed the color name in the rich text box, and changed the color of the start button which is not at all what I want. The eventual idea will be that everything that is typed that is the same, will be of that color. I figured this would be the simplest way of accomplishing that.
This is what I typed:
if(TypeHere.Text == DisplayText.Text)
{
DisplayText.Text = Convert.ToString(ForeColor = System.Drawing.Color.Blue);
}
That obviously didn't work like I thought it would. I'm sure I'm either missing a crucial step, or not entirely understanding how colors work on WF. I placed this in the TypeHere. The output of this in DisplayText is:
Color[Blue]
It wouldn't let me just set DisplayText to equal the color implicitly. I realize why it displays the name in the textbox, but I don't understand why it changes the color of the text in my button? I've tried it both as a method, and a couple of lines of code in the text box. So it's obviously not where I place the code, but something else.
Set the ForeColor property of the RichTextBox. This will change the font color in the RichTextBox.
richTextBox1.ForeColor = Color.Blue;
I have a problem with character spacing.
Basically I have something like this which comes from a txt file:
****************
*System Details*
****************
Looks nice and uniform, however, when I open have this go into a RichTextBox this happens:
Irregular character spacing example:
I've tried all different properties to try and stretch it, render it etc. but nothing works.
The data is coming in from code-behind OpenDialogBox that stores all the lines of the file in a string[]. A foreach loop then sends the lines into the RTB. (It needs to be a loop as each line gets checked)
Any help it greatly appreciated!
Many thanks
This is most likely a font choice problem. By default WPF uses Segoe UI on Windows 7 and above which is a non-monospaced font. This means that each character will not necessarily take up the same amount of space as each other character leading to issues if you are trying to align characters between lines. The easiest way to get alignment to work is by changing the font to a monospaced font by setting the FontFamily property on the RichTextBox.
How do I set the background color of a piece of text in a PDF document using iTextSharp without taking a form field?
The answer in this post uses a FormField, which according to me is an overkill and too long-winded a way to do something really simple.
Is there a simple way of coloring the background of a piece of text?
You can use the method SetBackground that is available in the Chunk class. There are two variations of this method: one that takes default padding and one that allows you to change the padding.
If you use the onGenericTag() method on a Chunk, you can draw a custom background (and do much more). For instance: you'd use onGenericTag() if you want to draw a rectangle with rounded corners. See my answer to your duplicate question Draw a rectangle at the *current position* and then get its position coordinates
After some trying, I have come to the conclusion that there are 3 ways to do this other than using the FormField (which is the fourth way and how to do that is already linked in the question):
1) Judging from this answer to another similar question, it appears as though there is no concept of a background color for text in the PDF specification. Therefore, one has to draw a rectangle at an absolute position before drawing the text (at that position).
This is like drawing on a Win32 DeviceContext.
2) You can draw a table and set the background color of the cell in which you want a background color.
3) You can write a chunk. The Chunk class has a method named SetBackground(). This doesn't look very nice because it doesn't let you control the padding around the text and between the borders of the box. You can control how far above the baseline the bottom of the text will appear by calling the chunk.SetTextRise(float f) method but that's about it. Still, it's a fast and easy way to get things done if you don't want too much beautification.
I wanted to show some mathematical expressions in a winforms textbox. So I thought the "Cambria Math" font would be a good choice but the text looked strange due the high top and bottom margin of the font. First I thought I made a mistake but according to this question, it's the correct behavior of the font.
Why does Cambria Math have these big margin values and how can I display my string correctly in the textbox like Word 2010?
(Note that I know only a little bit about typography ;)
Edit: I had to make the textbox that tall otherwise the caret would be invisible. The font size of the textbox is set to 8.25pt
Cambria Math uses Microsoft's mathematical OpenType extensions.
Word 2007 and later understand these and display the text with reasonable spacing.
However, notepad and Word 2000 display the text with enormous spacing, just like winforms. I guess the font has this much space by default because some characters (like U+2320, top half integral) are much larger than the alphanumerics.
If you use Cambria Math with a font engine (such as the one used by winforms) that doesn't understand the math extensions, you're going to get the big spacing.
If you're displaying simple expressions you might as well use Cambria.
i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.
Ex: i Typed Ram then it gives *Ram*esh .
The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.
That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.
I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.