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.
Related
I have a problem with the alignment of a few names (changed for this question).
with this code I display the names in a richtextbox where it should be in one row with the "Spalte:" after the Names...but it doesn't. Can anybody help me please?
(only the first for-loop is necessary for my question, the next one does another job)
I added a pic what it looks like and how it should be looking. I know I can do it like its in the commented area (doesn't work in every case), but I need to change the code for a few other things so this needs to work....
Here is what I have:
And here is what I want:
Thanks for helping me :D
You have four options:
Change the code for the RichTextBox to use a fixed-width font. Most fonts have variable widths for each character, meaning you can't line things up neatly based on spacing alone.
Use tabs instead of spaces for the layout (and make sure the tab size is large enough to account for variances in your text).
Use a grid control of some type (DataGrid, GridView, etc)
Use a custom control for each row with labels at specific places (and either calculate positions yourself to place them on the form or use something like a FlowLayoutPanel).
I have a Button in a Canvas, and when I set text button with English text, it works correct, but when set with Thai text, it delays up to 6 seconds (bad performance).
First I thought it was because I load many sounds and images, but after removing all of them, it's still slow, and if I change my Thai text, it works fast.
Does anyone know how to fix this issue?
public Text text;
void Start () {
text.text = "เพลงจิ้งจก";
}
I tried changing the font (Thonburi font), but no affect. So, my solution is change that text to image, which is a bad solution but cannot find any useful ways.
Last version of Unity has some performance issue on asian font due frequent call of iphone::GetFontPath() in RequestCharactersInTexture
A possible solution is track all characters used on application (I have script that do it) and set a special font as custom set with all characters used.
It is very hard to maintain but boost performance.
This is a hacky method, but if you only have a few lines of text that you need and they can be determined ahead of time, you could just load all of them on startup with a transparent color or off screen, then change the color or move it in when you need it.
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.
Hi all i am having a text file which consists of some data and each and every line in that particular is fixed to 94. Now when the user opened the particular text file and if my condition satisfies i will show it to datagridview. But when displaying to datagridview even the length of each and every line is 94 the content displaying in grid varies why it is happening . How to make sure that each and every row in datagridview should be displayed in a constant way
Any idea please
You're using a non-proportional font in the grid, which means that not all characters have the same size. F.e. spaces are way shorter then the 0. Use a proportional font, and the lines will be the same length.
Edit: Let's have a look at an example:
This is a non-proportional font,
the line will have different lengths,
though they are 10 characters long:
1234567890
adilngvzus
Now let's look at a proportional font:
1234567890
adilngvzus
As you can see, in a proportional font (like your IDE is most likely using) every characters has the same width. In a non-proportional font (like your text-processor is most likely using by default) the characters are varying in width, making the i one of the 'thinest' and the O one of the 'widest' characters.
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